title: Android - getListView and setListAdapter error with NullPointerException when using custom layout
body: <p>I have a layout like this</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
           android:orientation="vertical"
           android:layout_width="match_parent"
           android:layout_height="match_parent"
           android:background="#ffffff"&gt;
  
      &lt;com.ftni.core.ui.ActionBar
          android:id="@+id/actionbar"
          style="@style/ActionBar"/&gt;
  
      &lt;TextView android:id="@+id/list_title"
           android:layout_width="fill_parent"
           android:layout_height="wrap_content"
           android:text="Title"
           android:textStyle="bold"
           android:textColor="#000000"
           android:textSize="18sp"
           android:padding="3px"/&gt;
  
       &lt;ListView android:id="@id/android:list"
           android:layout_width="match_parent"
           android:layout_height="match_parent"
           android:layout_weight="1"
           android:drawSelectorOnTop="false"/&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>and in my listview (code that was working before I changed the layout)</p>
  
  <pre><code>private void buildListView()
  {
      ListView lv = getListView();
  
      registerForContextMenu(lv);
  
      lv.setTextFilterEnabled(true);
  
      lv.clearChoices();
  
      setListAdapter(new UserListAdapter(SuspendedUsersActivity.this, R.layout.useritem, users));
  
      lv.setOnItemClickListener(clickListener);
  }
  </code></pre>
  
  <p>I tried moving the call to <code>setListAdapter</code> first, but I still get the NullPointerException.  Here's the logcat</p>
  
  <pre><code>FATAL EXCEPTION: main
  java.lang.NullPointerException
  at android.app.ListActivity.setListAdapter(ListActivity.java:267)
  at com.myapp.backoffice.users.SuspendedUsersActivity.buildListView(SuspendedUsersActivity.java:140)
  at com.myapp.backoffice.users.SuspendedUsersActivity.access$0(SuspendedUsersActivity.java:138)
  at com.myapp.backoffice.users.SuspendedUsersActivity$2.handleMessage(SuspendedUsersActivity.java:194)
  at android.os.Handler.dispatchMessage(Handler.java:99)
  </code></pre>
  
  <p>I have a feeling that what is happening is that the default ID I was told is correct (<code>@id/android:list</code>) is not correct for the default list view.</p>
  
  <p>EDIT:</p>
  
  <p>Here are more details about how I have this set up.</p>
  
  <p>First, I have an inherited activity to ensure the user is authenticated.  When I inherit directly from this class, all works fine.</p>
  
  <pre><code>public class ProtectedListActivity extends ListActivityBase {
      boolean isAuthenticated = false;
  
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          Thread validationThread = new Thread()
          {
              @Override
              public void run() 
              {
                  try
                  {
                      isAuthenticated = UserService.ValidateToken();
                  }
                  catch (FTNIServiceException e)
                  {
                      //eat it
                  }
                  finally 
                  {
                      if (!isAuthenticated)
                      {
                          startActivity(new Intent(ProtectedListActivity.this, SignInActivity.class));
                          finish();
                      }
                  }
              }
          };
  
          validationThread.start();
      }
  }
  </code></pre>
  
  <p>Then, I extend that one step further to wrap my default action bar setup into a base class.</p>
  
  <pre><code>public class ListWithActionBarActivity extends ProtectedListActivity {
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
      }
  
      @Override
      public void onContentChanged()
      {
          ActionBar actionBar = (ActionBar)findViewById(R.id.actionbar);
          if (actionBar != null)
          {
              actionBar.setOnTitleClickListener(new OnClickListener() {
                  public void onClick(View v) {
                      startActivity(new Intent(ListWithActionBarActivity.this, SelectSiteActivity.class));
                      finish();
                  }
              });
  
              SiteModel site = PreferencesHelper.getSite();
  
              actionBar.setTitle(site.Name + " (" + site.Abbreviation + ")");
              actionBar.addAction(new IntentAction(ListWithActionBarActivity.this, 
                      new Intent(ListWithActionBarActivity.this, MainMenuActivity.class), 
                      R.drawable.ic_title_home_default));
          }
      }
  
      public static Intent createIntent(Context context) {
          Intent i = new Intent(context, MainMenuActivity.class);
          i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
          return i;
      }
  
      protected Intent createShareIntent() {
          final Intent intent = new Intent(Intent.ACTION_SEND);
          intent.setType("text/plain");
          intent.putExtra(Intent.EXTRA_TEXT, "Shared from the ActionBar widget.");
          return Intent.createChooser(intent, "Share");
      }
  }
  </code></pre>
  
  <p>Then, because I have 2 lists of users separated by status (suspended or active) I was attempting to wrap an addition to the action bar in a base class.</p>
  
  <pre><code>public class UserBase extends ListWithActionBarActivity {
      @Override
      public void onCreate(Bundle savedInstanceState) {
          //setContentView(R.layout.queue);
          super.onCreate(savedInstanceState);
  
          ActionBar actionBar = (ActionBar)findViewById(R.id.actionbar);
  
          actionBar.addAction(new UserStatusSelectorAction(UserBase.this));
  
      }
  }
  </code></pre>
  
  <p>and finally, we have my activity.  I've omitted a little code, but I left most of it so you could see how the data is retrieved through another thread while a loading screen is shown, and then the listview is built.</p>
  
  <pre><code>public class SuspendedUsersActivity extends ListWithActionBarActivity implements Runnable{
      ProgressDialog progress;
      ArrayList&lt;UserModel&gt; users;
      int position;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          setContentView(R.layout.queue);
          super.onCreate(savedInstanceState);
  
          TextView title = (TextView)findViewById(R.id.list_title);
          title.setText("Suspended Users");
  
          progress = ProgressDialog.show(SuspendedUsersActivity.this, "", "Loading...", true);
  
          Thread thread = new Thread(SuspendedUsersActivity.this);
          thread.start();
      }
  
      private void buildListView()
      {
          ListView lv = getListView();
  
          //registerForContextMenu(lv);
  
          lv.setTextFilterEnabled(true);
  
          lv.clearChoices();
  
          setListAdapter(new UserListAdapter(SuspendedUsersActivity.this, R.layout.useritem, users));
  
          lv.setOnItemClickListener(clickListener);
      }
  
      private OnItemClickListener clickListener = new OnItemClickListener()
      {
          @Override
          public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
              UserModel user = users.get(position);
  
              SuspendedUserAction action = new SuspendedUserAction(SuspendedUsersActivity.this, user.UserId);
              action.performAction(view);
          }
      };
  
      @Override
      public void run() {
          // TODO Auto-generated method stub
          SiteModel site = PreferencesHelper.getSite();
  
          try 
          {
              users = UserService.GetSuspendedUsers(site.SiteId);
          } 
          catch (FTNIServiceException e) 
          {
              // TODO Auto-generated catch block
              Message message = new Message();
              message.what = ActivityBase.RESULT_ERROR;
              message.obj = e.getMessage();
  
              handler.sendMessage(message);
              return;
          }
  
          handler.sendEmptyMessage(ActivityBase.RESULT_DONE);
      }
  
      private Handler handler = new Handler() {
          @Override
          public void handleMessage(Message msg) {
              switch(msg.what)
              {
                  case ActivityBase.RESULT_SUCCESS:
                      progress.dismiss();
                      startActivity(new Intent(SuspendedUsersActivity.this, SelectSiteActivity.class));
                      finish();
                      break;
                  case ActivityBase.RESULT_DONE:
                      buildListView();
                      ApplicationController app = (ApplicationController)getApplication();
                      app.setSuspendedUsersChanged(false);
                      progress.dismiss();
                      break;
                  case ActivityBase.RESULT_ERROR:
                      progress.dismiss();
                      new AlertDialog.Builder(SuspendedUsersActivity.this)
                      .setMessage(msg.obj.toString())
                      .setNeutralButton("Ok", new DialogInterface.OnClickListener() {
                          public void onClick(DialogInterface arg0, int arg1) {
                              //do nothing
                              arg0.dismiss();
                          }
                      })
                      .show();
                      break;
              }
          }
      };
  }
  </code></pre>
  
  <p>It works with ProtectedListActivity when I do not set a content view, but everything else it fails on, whether or not I set the content view and comment out the actionbar stuff.</p>