title: Getting NullPointerException in Custom ListView Adapter
body: <p>I am getting NullPointerException on <code>lv.setAdapter(adapter)</code>. I don't understand, I changed some codes in Adapter but then I removed them. And then this exception is started.</p>
  
  <p>In kimdenlistduzeltilmis : 4 value</p>
  
  <p><img src="https://i.stack.imgur.com/ElyAy.png" alt="enter image description here"></p>
  
  <p>In konulist : 4 value</p>
  
  <p><img src="https://i.stack.imgur.com/upCYi.png" alt="enter image description here"></p>
  
  <pre><code>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&lt;?&gt; 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();
                  }
  </code></pre>
  
  <p>And ListViewAdapter:</p>
  
  <pre><code>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&lt;Integer, Boolean&gt; cartItems = new HashMap&lt;Integer, Boolean&gt;();
      Context mContext;
      ArrayList&lt;String&gt; kimdenlist; // to load images
      ArrayList&lt;String&gt; konulist; // for data
  //  ArrayList&lt;String&gt; imagelist;
      LayoutInflater mLayoutInflater;
  
      public ListViewAdapter(Context context, ArrayList&lt;String&gt; kimdenlist, ArrayList&lt;String&gt; 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&lt;Integer, Boolean&gt; getcartItems() {
          return cartItems;
      }
  
      public void Remove()
         {
          notifyDataSetChanged();
         }
  
  }
  </code></pre>
  
  <p>And my Logcat:</p>
  
  <pre><code>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
  </code></pre>