title: ListviewArray Adaptor returns null pointer exception in customized layout
body: <p>My problem is,  I could not show the <code>ArrayList</code> data in <code>ListView</code>. My need is I have to show <code>listview</code> in my customized layout file center part. I have used custom adapter to show the <code>listview</code>. I am retrieving <code>ListArray&lt;String&gt;</code> data from my local database. <code>Listview</code> adapter does not receive my database <code>ArrayList&lt;String&gt;</code> item. I have created separate class for <code>ListAdaptor</code> and also created a constructor for <code>ListAdaptor</code>.</p>
  
  <p>I can able to show by extending <code>ListActivity</code>, But I have use <code>CustomAdaptor</code>. The following are my code, Please tell me where I did wrong code</p>
  
  <p><strong><em>Layout file(Dashboard_Notify.xml)</em></strong></p>
  
  <p>This is my customized layout xml file, In this page center i want to show listview data</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:background="@drawable/bg"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical" &gt;
  
      &lt;LinearLayout
          android:layout_width="wrap_content"
          android:layout_height="51dp"
          android:background="@drawable/dash_nav_bg_widout_brk_line"
          android:orientation="horizontal" &gt;
  
          &lt;ImageView
              android:id="@+id/imageButton1"
              android:layout_width="wrap_content"
              android:layout_height="match_parent"
              android:layout_marginLeft="0dp"
              android:layout_marginTop="0dp"
              android:src="@drawable/dash_nav_bg1_not_select" /&gt;
    &lt;ImageView
              android:id="@+id/imageButton1"
              android:layout_width="wrap_content"
              android:layout_height="match_parent"
              android:layout_marginLeft="0dp"
              android:layout_marginTop="0dp"
              android:src="@drawable/dash_nav_sep1" /&gt;
  
          &lt;ImageView
              android:id="@+id/imageButton1"
              android:layout_marginLeft="5dp"
              android:layout_width="90dp"
              android:layout_height="50dp"
              android:layout_marginTop="0dp"
              android:src="@drawable/dash_nav_bg1_bday" /&gt;
  
           &lt;ImageView
              android:id="@+id/imageButton1"
              android:layout_width="wrap_content"
              android:layout_height="match_parent"
              android:layout_marginLeft="4dp"
              android:layout_marginTop="0dp"
              android:src="@drawable/dash_nav_sep1" /&gt;
  
          &lt;ImageView
              android:id="@+id/imageButton1"
              android:layout_marginLeft="5dp"
              android:layout_width="wrap_content"
              android:layout_height="50dp"
              android:layout_marginTop="0dp"
              android:src="@drawable/dash_nav_bg1_sms" /&gt;
      &lt;/LinearLayout&gt;
  
      &lt;LinearLayout
          android:layout_width="280dp"
          android:layout_marginTop="30dp"
          android:layout_marginLeft="20dp"
          android:background="@drawable/dash_midl_bg_notify"
          android:layout_height="280dp"
          android:orientation="vertical" &gt;
  
          &lt;TextView
              android:id="@+id/textView1"
              android:paddingTop="8dp"
              android:layout_marginLeft="60dp"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="29 MAY" /&gt;
   &lt;View
          android:id="@+id/a"
          android:layout_width="match_parent"
          android:layout_height="1dp"
          android:layout_below="@+id/btnAdd"
          android:background="#8DB3E1" /&gt;
  
          &lt;ListView
              android:id="@+id/List"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:layout_below="@+id/a"
              android:divider="#8DB3E1"
              android:dividerHeight="2dp"
              android:headerDividersEnabled="true" /&gt;
  
      &lt;/LinearLayout&gt;
  
      &lt;ImageButton
          android:layout_marginLeft="70dp"
          android:layout_marginTop="30dp"
          android:id="@+id/imageButton2"
          android:layout_width="180dp"
          android:layout_height="37dp"
          android:src="@drawable/clear" /&gt;
  
  &lt;/LinearLayout&gt;
  
  
  
  
  ***//ListViewItem Row xml(BdayLlist.xml)***
  
  &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical" &gt;
  
           &lt;TableLayout
               android:layout_width="match_parent"
               android:layout_height="127dp"
               android:layout_marginTop="60dp" &gt;
  
               &lt;TableRow
                   android:layout_marginTop="20dp"
                   android:id="@+id/tableRow1"
                   android:layout_width="wrap_content"
                   android:layout_height="wrap_content" &gt;
  
                    &lt;LinearLayout
          android:layout_width="match_parent"
          android:orientation="horizontal"
          android:layout_height="wrap_content" &gt;
    &lt;TextView
          android:id="@+id/test_id"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="id" /&gt;
  
           &lt;TextView
          android:id="@+id/test_name"
          android:layout_marginLeft="10dp"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="vennila" /&gt;
  
            &lt;TextView
          android:id="@+id/test_Loc"
          android:layout_marginLeft="120dp"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Location" /&gt;
  
           &lt;/LinearLayout&gt;
  
               &lt;/TableRow&gt;
  
               &lt;TableRow
                   android:layout_marginTop="20dp"
                   android:id="@+id/tableRow2"
                   android:layout_width="wrap_content"
                   android:layout_height="wrap_content" &gt;
  
  
  
            &lt;TextView
          android:id="@+id/test_BDay"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Bday" /&gt;
  
  
              &lt;TextView
          android:id="@+id/test_Day"
          android:layout_marginLeft="-60dp"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Wednessday" /&gt;
  
  
               &lt;/TableRow&gt;
  
               &lt;TableRow
                   android:layout_marginTop="20dp"
                   android:id="@+id/tableRow3"
                   android:layout_width="wrap_content"
                   android:layout_height="wrap_content" &gt;
            &lt;TextView
          android:id="@+id/test_toDay"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Today" /&gt;
            &lt;TextView
                 android:layout_marginLeft="-60dp"
          android:id="@+id/test_Date"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="May 7" /&gt;
  
               &lt;/TableRow&gt;
  
  
           &lt;/TableLayout&gt;
  
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p><strong><em>MainActivity class(TodayList.java)</em></strong></p>
  
  <pre><code>package com.example.sampleparse;
  
  
  
  import java.text.SimpleDateFormat;
  import java.util.ArrayList;
  import java.util.Calendar;
  import java.util.HashMap;
  import java.util.List;
  
  import android.app.Activity;
  import android.app.ListActivity;
  import android.content.Context;
  import android.database.Cursor;
  import android.database.sqlite.SQLiteDatabase;
  import android.os.Bundle;
  import android.view.View;
  import android.widget.ArrayAdapter;
  import android.widget.ListView;
  import android.widget.Toast;
  
  public class TodayList extends Activity{
      SQLiteDatabase db;
      DbHelper dbh;
  ListView lv;
  private ArrayList&lt;String&gt; user_loc = new ArrayList&lt;String&gt;();
  
  private ArrayList&lt;String&gt; user_fName = new ArrayList&lt;String&gt;();
  private ArrayList&lt;String&gt; user_id = new ArrayList&lt;String&gt;();
  
   ArrayList&lt;String&gt; list= new ArrayList&lt;String&gt;();
  
   TestAdaptor ta;
   private ArrayAdapter&lt;String&gt; listAdapter ;  
  
       @Override
          public void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
            setContentView(R.layout.dashboard_notify);
            this.lv=(ListView) findViewById(R.id.List);
              try{
          // BdayList();
                  //Bname();
         //  displayData();
                   dbh=new DbHelper(this);
                   db=dbh.getWritableDatabase();
                   list=dbh.Bname();
  
                   String[] stockArr = new String[list.size()];
                   stockArr = list.toArray(stockArr);
                   for(String s : stockArr)
                          System.out.println(s);
                  // System.out.println(stockArr.toString());
  
                  /* user_loc=dbh.BLocation();
                   String[] loc = new String[user_loc.size()];
  
                   for(String l : loc)
                       System.out.println(l);*/
                   //ta = new  TestAdaptor(TodayList.this, stockArr,loc );
                   ListAdapter la = new ListAdapter(getApplicationContext(), list);
                   lv.setAdapter(la);
                  /* ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(this,
                              R.layout.bdaylist, R.id.test_name, stockArr);*/
  
                         // setListAdapter(adapter);   
  
              }catch(Exception e){
                  Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_LONG).show();
              }
       }
  
  
  
      public void Bname(){
           dbh=new DbHelper(this);
           db=dbh.getWritableDatabase();
           list=dbh.Bname();
           listAdapter = new ArrayAdapter&lt;String&gt;(this, R.layout.bdaylist, list); 
           Toast.makeText(getApplicationContext(), list.toString(), Toast.LENGTH_LONG).show();
           lv.setAdapter(listAdapter);
       }
  
       @Override
          protected void onResume() {
  
              super.onResume();
              //displayData();
          }
  
  
       //worked listView(){ code
       //should extends listActivity
       public void list(){
           dbh=new DbHelper(this);
           db=dbh.getWritableDatabase();
           list=dbh.Bname();
  
           String[] stockArr = new String[list.size()];
           stockArr = list.toArray(stockArr);
           for(String s : stockArr)
                  System.out.println(s);
          // System.out.println(stockArr.toString());
           ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(this,
                      R.layout.bdaylist, R.id.test_name, stockArr);
          //should uncomment the line
                  //setListAdapter(adapter);   
       }
  
       public void displayData() {
              db = dbh.getWritableDatabase();
               Calendar c = Calendar.getInstance();
                  SimpleDateFormat df1 = new SimpleDateFormat("dd/MM/yyyy");
                  String formattedDate1 = df1.format(c.getTime());
  
                  String sub = formattedDate1;
                  String s1=sub.substring(0, 5);
                  ArrayList&lt;String&gt; test=new ArrayList&lt;String&gt;();
             String selectQuery="SELECT * FROM " + dbh.TABLE_CONTACTS + " where dob = '" + s1 +"'";
              Cursor mCursor = db.rawQuery(selectQuery, null);
              user_id.clear();
              user_loc.clear();
              user_fName.clear();
  
              if (mCursor.moveToFirst()) {
                  do {
                      user_id.add(mCursor.getString(mCursor.getColumnIndex(DbHelper.KEY_ID)));
  
                      user_fName.add(mCursor.getString(mCursor.getColumnIndex(DbHelper.EMP_NAME)));
                      user_loc.add(mCursor.getString(mCursor.getColumnIndex(DbHelper.EMP_LOC)));
                      System.out.println("loc " + user_loc);
                      Toast.makeText(getApplicationContext(), user_id.toString()+" "+ user_fName.toString()+ " "+ user_loc.toString(), 1000).show();
                      //user_lName.add(mCursor.getString(mCursor.getColumnIndex(DbHelper.KEY_ASSID)));
                      //user_dob.add(mCursor.getString(mCursor.getColumnIndex(DbHelper.KEY_DOB)));
  
                      //user_mobno.add(mCursor.getString(mCursor.getColumnIndex(DbHelper.KEY_MOBNO)));
                      //user_email.add(mCursor.getString(mCursor.getColumnIndex(DbHelper.KEY_EMAIL)));
  
                  } while (mCursor.moveToNext());
              }
              ListAdapter disadpt = new ListAdapter(TodayList.this, user_fName );
              lv.setAdapter(disadpt);
              mCursor.close();
          }
  
  
  
  
  
       public void BdayList(){
  
           dbh=new DbHelper(this);
           db=dbh.getWritableDatabase();
          list= dbh.DOB();
          // listAdapter = new ArrayAdapter&lt;String&gt;(this, R.layout.bdaylist, list);  
          Toast.makeText(getApplicationContext(), list.toString(), Toast.LENGTH_LONG).show();
  
          /*final StableArrayAdapter adapter = new StableArrayAdapter(TodayList.this,
                  android.R.layout.simple_list_item_1, list);*/
          listAdapter = new ArrayAdapter&lt;String&gt;(this, R.layout.simplrrow, list);
              lv.setAdapter(listAdapter);
  
       }
  
       private class StableArrayAdapter extends ArrayAdapter&lt;String&gt; {
  
              HashMap&lt;String, Integer&gt; mIdMap = new HashMap&lt;String, Integer&gt;();
  
              public StableArrayAdapter(Context context, int textViewResourceId,
                  List&lt;String&gt; objects) {
                super(context, textViewResourceId, objects);
                for (int i = 0; i &lt; objects.size(); ++i) {
                  mIdMap.put(objects.get(i), i);
                }
              }
  
              @Override
              public long getItemId(int position) {
                String item = getItem(position);
                return mIdMap.get(item);
              }
  
              @Override
              public boolean hasStableIds() {
                return true;
              }
  
            }
  
  }
  </code></pre>
  
  <p><strong><em>Custom Adaptor class(ListAdaptor.java)</em></strong></p>
  
  <pre><code>package com.example.sampleparse;
  
  import java.util.ArrayList;
  
  import android.content.Context;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.BaseAdapter;
  import android.widget.TextView;
  
  public class ListAdapter extends BaseAdapter{
      private Context mContext;
      private ArrayList&lt;String&gt; id;
      private ArrayList&lt;String&gt; Name;
      private ArrayList&lt;String&gt; Assid;
  
      private ArrayList&lt;String&gt; Dob;
      private ArrayList&lt;String&gt; Mobno;
      private ArrayList&lt;String&gt; Email;
      private ArrayList&lt;String&gt; dept;
      private ArrayList&lt;String&gt; location;
  
      public ListAdapter(Context c,  ArrayList&lt;String&gt; name) {
          this.mContext = c;
  
          //this.id = id;
          this.Name = name;
      /*  this.Assid = assid;
          this.Dob = user_dob;
          this.Mobno = user_mobno;
          this.Email = user_email;
          this.dept = dept;*/
          //this.location = loc;
      }
  
  
      @Override
      public int getCount() {
          // TODO Auto-generated method stub
          return Name.size();
      }
  
      @Override
      public Object getItem(int arg0) {
          // TODO Auto-generated method stub
          return Integer.valueOf(arg0);
      }
      public void setAllItems(ArrayList&lt;String&gt; paramArrayList) {
          this.Name.addAll(paramArrayList);
      }
  
      @Override
      public long getItemId(int arg0) {
          // TODO Auto-generated method stub
          return arg0;
      }
  
      @Override
      public View getView(int pos, View child, ViewGroup parent) {
          // TODO Auto-generated method stub
  
          Holder mHolder;
          LayoutInflater layoutInflater;
          layoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          if (child == null) {
              mHolder = new Holder();
              child = layoutInflater.inflate(R.layout.bdaylist, parent, false);
              mHolder = new Holder();
              /* localViewholder.categoryName = ((TextView) paramView
                          .findViewById(R.id.name));
  
                  paramView.setTag(localViewholder);*/
          //  mHolder.
              mHolder.txt_id = (TextView) child.findViewById(R.id.test_id);
              mHolder.txt_Name = (TextView) child.findViewById(R.id.test_name);
              mHolder.txt_Loc = (TextView) child.findViewById(R.id.test_Loc);
  
              mHolder.txt_Bday = (TextView) child.findViewById(R.id.test_BDay);
              mHolder.txt_Day= (TextView) child.findViewById(R.id.test_Day);
              mHolder.txt_Today= (TextView) child.findViewById(R.id.test_toDay);
              mHolder.txt_Date = (TextView) child.findViewById(R.id.test_Date);
  
              child.setTag(mHolder);
          } else {
              mHolder = (Holder) child.getTag();
          }
  
          mHolder.txt_id.setText("id");
          mHolder.txt_Name.setText(Name.get(pos).indexOf(0));
          mHolder.txt_Loc.setText(":lov");
  
          mHolder.txt_Bday.setText("Birth Day");
          mHolder.txt_Day.setText("WEdness day");
          mHolder.txt_Today.setText("Today");
          mHolder.txt_Date.setText("May 7");
          mHolder.txt_Loc.setText("loc");
          return child;
  
  
      }
  
      public class Holder {
          TextView txt_id;
          TextView txt_Name;
          TextView txt_Bday;
  
          TextView txt_Day;
          TextView txt_Today;
          TextView txt_Date;
          TextView txt_Loc;
  
      }
  
  }
  </code></pre>
  
  <p>Please give me a solution, I spent stuck in this concept more than one day.</p>