title: Getting NullPointerException in custom ListView
body: <p>I'm getting errors like this when I run my app:</p>
  
  <pre><code>02-27 22:59:19.331: E/AndroidRuntime(2060): FATAL EXCEPTION: main
  02-27 22:59:19.331: E/AndroidRuntime(2060): java.lang.NullPointerException
  02-27 22:59:19.331: E/AndroidRuntime(2060):     
          at myPlanAdapter.getView(MyPlanActivity.java:145)
          02-27 22:59:19.331: E/AndroidRuntime(2060):     at android.widget.AbsListView.obtainView(AbsListView.java:1315)
      02-27 22:59:19.331: E/AndroidRuntime(2060):     at android.widget.ListView.measureHeightOfChildren(ListView.java:1198)
      02-27 22:59:19.331: E/AndroidRuntime(2060):     at android.widget.ListView.onMeasure(ListView.java:1109)
      02-27 22:59:19.331: E/AndroidRuntime(2060):     at android.view.View.measure(View.java:8171)
      02-27 22:59:19.331: E/AndroidRuntime(2060):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
      02-27 22:59:19.331: E/AndroidRuntime(2060):     at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1012)
      02-27 22:59:19.331: E/AndroidRuntime(2060):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:381)
      02-27 22:59:19.331: E/AndroidRuntime(2060):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
      02-27 22:59:19.331: E/AndroidRuntime(2060):     at android.view.View.measure(View.java:8171)
      02-27 22:59:19.331: E/AndroidRuntime(2060):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
      02-27 22:59:19.331: E/AndroidRuntime(2060):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
      02-27 22:59:19.331: E/AndroidRuntime(2060):     at android.view.View.measure(View.java:8171)
      02-27 22:59:19.331: E/AndroidRuntime(2060):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
      02-27 22:59:19.331: E/AndroidRuntime(2060):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
      02-27 22:59:19.331: E/AndroidRuntime(2060):     at android.view.View.measure(View.java:8171)
      02-27 22:59:19.331: E/AndroidRuntime(2060):     at android.view.ViewRoot.performTraversals(ViewRoot.java:801)
      02-27 22:59:19.331: E/AndroidRuntime(2060):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
      02-27 22:59:19.331: E/AndroidRuntime(2060):     at android.os.Handler.dispatchMessage(Handler.java:99)
      02-27 22:59:19.331: E/AndroidRuntime(2060):     at android.os.Looper.loop(Looper.java:123)
      02-27 22:59:19.331: E/AndroidRuntime(2060):     at android.app.ActivityThread.main(ActivityThread.java:4627)
      02-27 22:59:19.331: E/AndroidRuntime(2060):     at java.lang.reflect.Method.invokeNative(Native Method)
      02-27 22:59:19.331: E/AndroidRuntime(2060):     at java.lang.reflect.Method.invoke(Method.java:521)
      02-27 22:59:19.331: E/AndroidRuntime(2060):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
  </code></pre>
  
  <p>And my Source code is:</p>
  
  <pre><code>public class MyPlanActivity extends Activity implements OnItemClickListener,
          OnClickListener {
      private String TAG = "MyPlanActivity";
      private Button addButton = null;
      private ListView listView;
      myPlanAdapter adapter;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          // TODO Auto-generated method stub
          super.onCreate(savedInstanceState);
          viewInit();
          adapter = new myPlanAdapter(getBaseContext());
          listView.setAdapter(adapter);
          listView.setOnItemClickListener(this);
  
      }
  
      private void viewInit() {
          setContentView(R.layout.myplan);
          addButton = (Button) findViewById(R.id.AddMyPlanButtonId);
          listView = (ListView) findViewById(R.id.myPlanListViewId);
          addButton.setOnClickListener(this);
  
      }
  
      public void onClick(View v) {
          switch (v.getId()) {
          case R.id.AddMyPlanButtonId:
              startActivity(new Intent(this, AddMyPlan.class));
              break;
  
          default:
              break;
          }
      }
  
      public void onItemClick(AdapterView&lt;?&gt; paramAdapterView, View paramView,
              int paramInt, long paramLong) {
          // TODO Auto-generated method stub
  
      }
  
      @Override
      protected void onResume() {
          super.onResume();
          adapter.notifyDataSetChanged();
      }
  
      private class myPlanAdapter extends ArrayAdapter&lt;MyPlan&gt; {
          Context context;
          MyPlanDataSource dataSource;
  
          public myPlanAdapter(Context context) {
              super(context, R.layout.myplan_list_view_entry);
              this.context = context;
              dataSource = new MyPlanDataSource(context);
          }
  
          private ArrayList&lt;MyPlan&gt; getAllPlan() {
  
              dataSource.open();
              ArrayList&lt;MyPlan&gt; allPlan = dataSource.getAllPlan();
              dataSource.close();
              Log.d(TAG,allPlan.get(0).getSubjectName());
              return allPlan;
          }
  
          @Override
          public int getCount() {
              Log.d(TAG,"Size: "+getAllPlan().size());
              return getAllPlan().size();
          }
  
          @Override
          public MyPlan getItem(int position) {
              return getAllPlan().get(position);
          }
  
          @Override
          public View getView(final int position, View convertView,
                  ViewGroup parent) {
              View row = convertView;
              if (row == null)
              {
                  LayoutInflater inflater = (LayoutInflater) context
                          .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                  row = inflater.inflate(R.layout.myplan_list_view_entry, parent,
                          false);
  
                  final PlanViewHolder viewHolder = new PlanViewHolder();
  
                  viewHolder.subjectName = (TextView) findViewById(R.id.myPlanListSubNameTextViewId);
                  viewHolder.targetGrade = (TextView) findViewById(R.id.myPlanListTargetGradeTextViewId);
                  viewHolder.duration = (TextView) findViewById(R.id.myPlanListDurationTextViewId);
                  viewHolder.examDate = (TextView) findViewById(R.id.myPlanListExamDateTextViewId);
                  viewHolder.daysTogo = (TextView) findViewById(R.id.myplanListDaystogoBoardTextViewId);
                  viewHolder.delete = (ImageView) findViewById(R.id.myPlanDeleteImageViewId);
                  Log.d(TAG, "" + position);
  
                  row.setTag(viewHolder);
              }
              final PlanViewHolder holder = (PlanViewHolder) row.getTag();
  
  
              holder.subjectName.setText((getAllPlan().get(position) 
                      .getSubjectName())); // line 145
              holder.targetGrade.setText("Grade : "
                      + getAllPlan().get(position).getTargetGrade());
              holder.duration.setText(getAllPlan().get(position).getExamTime());
              holder.examDate.setText(getAllPlan().get(position).getExamDate());
  
  
  
              holder.daysTogo.setText(getAllPlan().get(position).getDaysTogo());
  
              holder.delete.setOnClickListener(new OnClickListener() {
  
                  public void onClick(View v) {
                      AlertDialog.Builder builder = new AlertDialog.Builder(
                              context);
                      builder.setTitle("DELETE")
                              .setMessage(
                                      "Are you sure you want to delete this Subject?")
                              .setCancelable(false)
                              .setPositiveButton("Yes",
                                      new DialogInterface.OnClickListener()
                                      {
                                          public void onClick(
                                                  DialogInterface dialog, int id)
                                          {
  
                                              dataSource.open();
                                              dataSource
                                                      .deletePlan(getItem(position));
                                              dataSource.close();
                                              notifyDataSetChanged();
                                          }
                                      })
                              .setNegativeButton("No",
                                      new DialogInterface.OnClickListener()
                                      {
                                          public void onClick(
                                                  DialogInterface dialog, int id)
                                          {
                                              dialog.cancel();
                                          }
                                      });
                      AlertDialog alert = builder.create();
                      alert.show();
  
                  }
              });
  
  
              return row;
          }
      }
  
      static class PlanViewHolder {
          private TextView subjectName;
          private TextView targetGrade;
          private TextView duration;
          private TextView examDate;
          private TextView daysTogo;
          private ImageView delete;
      }
  
  }
  </code></pre>