title: how to work with Checkbox in Custom Adapter
body: <p>I am working with checkbox which is in my custom Adapter.I used the Interface in Activity to send that checkbox text in another listview the problem i am facing that when i add the item to checkbox and checked the checkbox the application get stop working..but when i reopen the app and try to checked its again its workfine.when i try to add one new item to checkbox same issue happen and vice-versa</p>
  
  <p>Logcat error:</p>
  
  <pre><code>  java.lang.NullPointerException: Attempt to invoke interface method 'void com.advoco.notepad.ListAdapter$onItemChecked.onItemClick(int)' on a null object reference
                                                                    at com.advoco.notepad.ListAdapter$1.onCheckedChanged(ListAdapter.java:51)
                                                                    at android.widget.CompoundButton.setChecked(CompoundButton.java:156)
                                                                    at android.widget.CompoundButton.toggle(CompoundButton.java:115)
                                                                    at android.widget.CompoundButton.performClick(CompoundButton.java:120)
                                                                    at android.view.View$PerformClick.run(View.java:22429)
                                                                    at android.os.Handler.handleCallback(Handler.java:751)
                                                                    at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                    at android.os.Looper.loop(Looper.java:154)
                                                                    at android.app.ActivityThread.main(ActivityThread.java:6119)
                                                                    at java.lang.reflect.Method.invoke(Native Method)
                                                                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
                                                                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
  
  
  public class ListAdapter extends ArrayAdapter&lt;NoteDone&gt; {
  Context context;
  LayoutInflater inflater;
  List&lt;NoteDone&gt; noteDones;
  private onItemChecked onClick;
  public ListAdapter(Context context,int resource,List&lt;NoteDone&gt; noteDones) {
      super(context, resource,noteDones);
      this.context = context;
      this.noteDones = noteDones;
      inflater = LayoutInflater.from(context);
  }
  private class ViewHolder {
      TextView notDone;
      CheckBox checkBox;
  }
  public interface onItemChecked{
      void onItemClick(int position);
  }
  public View getView(final int position, View view, ViewGroup parent) {
      final ListAdapter.ViewHolder holder;
      final NoteDone model = noteDones.get(position);
      if (view == null) {
          holder = new ListAdapter.ViewHolder();
          view = inflater.inflate(R.layout.notdone, null);
          holder.checkBox = (CheckBox) view.findViewById(R.id.checkBox);
          view.setTag(holder);
      } else {
          holder = (ListAdapter.ViewHolder) view.getTag();
      }
      holder.checkBox.setText(model.getTask());
      holder.checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
          @Override
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
              onClick.onItemClick(position);
          }
      });
      return view;
  }
  public void setOnClick(onItemChecked onClick)
  {
      this.onClick=onClick;
  }
  }
  </code></pre>
  
  <p>My activity class:</p>
  
  <pre><code>public class ToDo extends AppCompatActivity implements 
  ListAdapter.onItemChecked{
  DBhelper dBhelper;
  ListView lstTask,listView;
  List&lt;NoteDone&gt; taskList,tasklist2;
  ListAdapter listAdapter;
  ListAdapter2 listAdapter2;
  SQLiteDatabase sqLiteDatabase;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.todo);
      lstTask = (ListView)findViewById(R.id.nd);
      listView = (ListView)findViewById(R.id.done);
      LoadTask();
      LoadTask2();
      listAdapter.setOnClick(this);
     /*lstTask.setOnItemClickListener(new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
              String name = taskList.get(position).getTask();
              dBhelper.insertNewTask2(name);
              dBhelper.deleteTask(name);
              LoadTask();
              LoadTask2();
          }
      });*/
  }
  public void LoadTask() {
      dBhelper = new DBhelper(getApplicationContext());
      sqLiteDatabase = dBhelper.getReadableDatabase();
      taskList = dBhelper.getTaskList(sqLiteDatabase);
      if (taskList != null) {
          listAdapter = new ListAdapter(getApplicationContext(), R.layout.notdone, taskList);
          lstTask.setAdapter(listAdapter);
      }
  }
  public void LoadTask2() {
      dBhelper = new DBhelper(getApplicationContext());
      sqLiteDatabase = dBhelper.getReadableDatabase();
      tasklist2 = dBhelper.getTaskList2(sqLiteDatabase);
      if (tasklist2 != null) {
          listAdapter2 = new ListAdapter2(getApplicationContext(), R.layout.done, tasklist2);
          listView.setAdapter(listAdapter2);
      }
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      MenuInflater inflater = getMenuInflater();
      inflater.inflate(R.menu.todo_menu, menu);
      return super.onCreateOptionsMenu(menu);
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      switch (item.getItemId()){
          case R.id.action_add_task:
              final EditText taskEditText = new EditText(this);
              AlertDialog dialog = new AlertDialog.Builder(this)
                      .setTitle("Add New Task")
                      .setMessage("What do you want to do next?")
                      .setView(taskEditText)
                      .setPositiveButton("Add", new DialogInterface.OnClickListener() {
                          @Override
                          public void onClick(DialogInterface dialog, int which) {
                              String task = String.valueOf(taskEditText.getText());
                              dBhelper.insertNewTask(task);
                              LoadTask();
                          }
                      })
                      .setNegativeButton("Cancel",null)
                      .create();
              dialog.show();
              return true;
      }
      return super.onOptionsItemSelected(item);
  }
  
  @Override
  public void onItemClick(int position) {
      String name = taskList.get(position).getTask();
      dBhelper.insertNewTask2(name);
      dBhelper.deleteTask(name);
      LoadTask();
      LoadTask2();
  }
  }
  </code></pre>