0

で NullPointerException が発生していlv.setAdapter(adapter)ます。わかりません。Adapter でいくつかのコードを変更しましたが、それらを削除しました。そして、この例外が開始されます。

kimdenlistduzeltilmis : 4 値

ここに画像の説明を入力

konulist で : 4 つの値

ここに画像の説明を入力

final LayoutInflater mLInflater = getLayoutInflater();
        final ListViewAdapter adapter = new ListViewAdapter(
                getApplicationContext(), kimdenlistduzeltilmis, konulist,
                mLInflater);
        lv.setAdapter(adapter);
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View item,
                    int position, long id) {
                // adapter.Refresh();
                onClickPosition = position;
                try {
                    EkDurumu ekdurumuNesnesi = new EkDurumu();
                    ekdurumuNesnesi.MessagePositionEkBulunuyormu(
                            onClickPosition, goruntuleNesnesi.getMessages());

                } catch (Exception e) {
                    e.printStackTrace();
                }

そしてListViewAdapter:

import java.util.ArrayList;
import java.util.HashMap;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.CompoundButton.OnCheckedChangeListener;

public class ListViewAdapter extends BaseAdapter {
    static HashMap<Integer, Boolean> cartItems = new HashMap<Integer, Boolean>();
    Context mContext;
    ArrayList<String> kimdenlist; // to load images
    ArrayList<String> konulist; // for data
//  ArrayList<String> imagelist;
    LayoutInflater mLayoutInflater;

    public ListViewAdapter(Context context, ArrayList<String> kimdenlist, ArrayList<String> konulist,
            LayoutInflater layoutInflater) {
        mContext = context;
        this.kimdenlist = kimdenlist;
        this.konulist = konulist;
        mLayoutInflater = layoutInflater;
    }

    @Override
    public int getCount() 
    {
        return konulist.size(); // images array length
    }

    @Override
    public Object getItem(int arg0) {

        return null;
    }

    @Override
    public long getItemId(int arg0) {

        return 0;
    }

    int count = 0;

    // customized Listview
    @Override
    public View getView(int position, View arg1, ViewGroup arg2) {

        View v;
        final int pos = position;
        v = mLayoutInflater.inflate(R.layout.listust, null);

        TextView kimden = (TextView) v.findViewById(R.id.textvKimden);
        kimden.setText(kimdenlist.get(position));
        TextView konu = (TextView) v.findViewById(R.id.textvKonu);
        konu.setText(konulist.get(position));

//      // saving check box state at the time of raloading
        CheckBox ch = (CheckBox) v.findViewById(R.id.chk);
        try {
            if (count != 0) {
                boolean b = cartItems.get(pos);
                if (b == false)
                    ch.setChecked(false);
                else
                    ch.setChecked(true);
            }
        } catch (NullPointerException e) {

        }


        ch.setOnCheckedChangeListener(new OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
                cartItems.put(pos, arg1);
                count++;

            }
        });
        return v;
    }

    public static HashMap<Integer, Boolean> getcartItems() {
        return cartItems;
    }

    public void Remove()
       {
        notifyDataSetChanged();
       }

}

そして私のLogcat:

05-16 16:13:12.962: E/AndroidRuntime(347): FATAL EXCEPTION: main
05-16 16:13:12.962: E/AndroidRuntime(347): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mobil.eposta/com.mobil.eposta.ListeleActivity}: java.lang.NullPointerException
05-16 16:13:12.962: E/AndroidRuntime(347):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
05-16 16:13:12.962: E/AndroidRuntime(347):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
05-16 16:13:12.962: E/AndroidRuntime(347):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
05-16 16:13:12.962: E/AndroidRuntime(347):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
05-16 16:13:12.962: E/AndroidRuntime(347):  at android.os.Handler.dispatchMessage(Handler.java:99)
05-16 16:13:12.962: E/AndroidRuntime(347):  at android.os.Looper.loop(Looper.java:123)
05-16 16:13:12.962: E/AndroidRuntime(347):  at android.app.ActivityThread.main(ActivityThread.java:4627)
05-16 16:13:12.962: E/AndroidRuntime(347):  at java.lang.reflect.Method.invokeNative(Native Method)
05-16 16:13:12.962: E/AndroidRuntime(347):  at java.lang.reflect.Method.invoke(Method.java:521)
05-16 16:13:12.962: E/AndroidRuntime(347):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-16 16:13:12.962: E/AndroidRuntime(347):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-16 16:13:12.962: E/AndroidRuntime(347):  at dalvik.system.NativeStart.main(Native Method)
05-16 16:13:12.962: E/AndroidRuntime(347): Caused by: java.lang.NullPointerException
05-16 16:13:12.962: E/AndroidRuntime(347):  at com.mobil.eposta.ListeleActivity.onCreate(ListeleActivity.java:109)
05-16 16:13:12.962: E/AndroidRuntime(347):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-16 16:13:12.962: E/AndroidRuntime(347):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
05-16 16:13:12.962: E/AndroidRuntime(347):  ... 11 more
4

1 に答える 1

1

ListView が null のようです。追加してみる

lv = (ListView) findViewById(R.id.whatever_id_you_gave_your_listview);

setAdapter() を呼び出す前に

于 2012-05-16T16:29:04.670 に答える