title: Custom listview adapter gives nullpointerexception
body: <p>I want to setup a fragment that shows up a listview. I tried it like this:</p>
  
  <p>MainActivity extends FragmentActivity</p>
  
  <p>In the onCreate:</p>
  
  <pre><code>   FragmentTransaction ft = getFragmentManager().beginTransaction();
          Inbox inbox = Inbox.newInstance();
          ft.replace(R.id.container, inbox);
          ft.commit();
  </code></pre>
  
  <p>In my Inbox fragment:</p>
  
  <pre><code>public static Inbox newInstance() {
      Inbox fragmentDemo = new Inbox();
      return fragmentDemo;
  }
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
  
      View view = inflater.inflate(R.layout.fragment_inbox, container, false);
  
      smsAdapter = new ListAdapter(getActivity(), smsList);
      ListView lv = (ListView) view.findViewById(R.id.list);
      lv.setAdapter(smsAdapter);
  
      return view;
  }
  </code></pre>
  
  <p>My custom ListAdapter:</p>
  
  <pre><code>public class ListAdapter extends ArrayAdapter&lt;SMSData&gt; {
  
  private String TAG = ListAdapter.class.getName();
  
  private final Context context;
  private final List&lt;SMSData&gt; smsList;
  
  public ListAdapter(Context context, List&lt;SMSData&gt; smsList) {
      super(context, R.layout.sms_inbox, smsList);
      this.context = context;
      this.smsList = smsList;
  }
  
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
      ViewHolder holder;
  
      if(convertView == null) {
          LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          convertView = inflater.inflate(R.layout.sms_inbox, parent, true);
  
          holder = new ViewHolder();
          holder.senderNumber = (TextView) convertView.findViewById(R.id.smsNumberText);
  
          convertView.setTag(holder);
      }
      else
          holder = (ViewHolder) convertView.getTag();
  
      holder.senderNumber.setText(smsList.get(position).getNumber());
  
      return convertView;
  }
  
  private static class ViewHolder
  {
      public TextView senderNumber;
  }
  }
  </code></pre>
  
  <p>Activity xml:</p>
  
  <pre><code>&lt;FrameLayout
      android:id="@+id/container"
      android:layout_height="match_parent"
      android:layout_width="match_parent"&gt;
  &lt;/FrameLayout&gt;
  </code></pre>
  
  <p>Fragment xml:</p>
  
  <pre><code>  &lt;ListView
          android:id="@+id/list"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"/&gt;
  </code></pre>
  
  <p>Sms_inbox.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
               android:layout_width="match_parent"
               android:layout_height="match_parent" &gt;
      &lt;TableRow&gt;
          &lt;TextView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:id="@+id/smsNumberText"/&gt;
      &lt;/TableRow&gt;
  &lt;/TableLayout&gt;
  </code></pre>
  
  <p>Gives me:</p>
  
  <pre><code>05-06 06:13:40.528    2756-2756/com.test E/AndroidRuntime﹕ FATAL EXCEPTION: main
      Process: com.test, PID: 2756
      java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test/com.test.MainActivity}: java.lang.NullPointerException
              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
              at android.app.ActivityThread.access$800(ActivityThread.java:135)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
              at android.os.Handler.dispatchMessage(Handler.java:102)
              at android.os.Looper.loop(Looper.java:136)
              at android.app.ActivityThread.main(ActivityThread.java:5017)
              at java.lang.reflect.Method.invokeNative(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:515)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
              at dalvik.system.NativeStart.main(Native Method)
       Caused by: java.lang.NullPointerException
              at android.widget.ArrayAdapter.getCount(ArrayAdapter.java:330)
              at android.widget.ListView.setAdapter(ListView.java:480)
              at Fragments.Inbox.onCreateView(Inbox.java:51)
              at android.app.Fragment.performCreateView(Fragment.java:1700)
              at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:890)
              at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1062)
              at android.app.BackStackRecord.run(BackStackRecord.java:684)
              at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1447)
              at android.app.Activity.performStart(Activity.java:5240)
              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2168)
              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
              at android.app.ActivityThread.access$800(ActivityThread.java:135)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
              at android.os.Handler.dispatchMessage(Handler.java:102)
              at android.os.Looper.loop(Looper.java:136)
              at android.app.ActivityThread.main(ActivityThread.java:5017)
              at java.lang.reflect.Method.invokeNative(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:515)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
              at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>Can someone help me out on this? I've seen many tutorials on the net and I don't see what I'm doing different. </p>