title: OnResume method throws NullPointerException
body: <p>I am trying to add an item in the action bar, but when I click on the item from <code>MainActivity</code>, it shows a NullPointer exception.
  It should start that activity. I have registered that activity in my Android manifest file as well !!
  Here is my code.</p>
  
  <pre><code>package milind.com.bluetooth_transmission;
  
  public class settings extends ActionBarActivity {
      TextView textConnectionStatus;
      ListView pairedListView;
      private BluetoothAdapter mBtAdapter;
      private ArrayAdapter&lt;String&gt; mPairedDevicesArrayAdapter;
  
      @Override
      public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState)
      {
          super.onCreate(savedInstanceState, persistentState);
          setContentView(R.layout.settings);
          // Member fields
          Intent intent = getIntent();
          textConnectionStatus = (TextView) findViewById(R.id.connecting);
          textConnectionStatus.setTextSize(40);
  
          // Initialize array adapter for paired devices
          mPairedDevicesArrayAdapter = new ArrayAdapter&lt;String&gt;(this, R.layout.device_name);
  
          // Find and set up the ListView for paired devices
          pairedListView = (ListView) findViewById(R.id.paired_devices);
          pairedListView.setAdapter(mPairedDevicesArrayAdapter);
  
  
      }
      @Override
      public void onResume()
      {
          super.onResume();
          //It is best to check BT status at onResume in case something has changed while app was paused etc
          checkBTState();
  
          mPairedDevicesArrayAdapter.clear();// clears the array so items aren't duplicated when resuming from onPause
  
          textConnectionStatus.setText(" "); //makes the textview blank
  
          // Get the local Bluetooth adapter
          mBtAdapter = BluetoothAdapter.getDefaultAdapter();
  
          // Get a set of currently paired devices and append to pairedDevices list
          Set&lt;BluetoothDevice&gt; pairedDevices = mBtAdapter.getBondedDevices();
  
          // Add previously paired devices to the array
          if (pairedDevices.size() &gt; 0) {
              findViewById(R.id.title_paired_devices).setVisibility(View.VISIBLE);//make title viewable
              for (BluetoothDevice device : pairedDevices) {
                  mPairedDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress());
              }
          } else {
              mPairedDevicesArrayAdapter.add("no devices paired");
          }
      }
  
      //method to check if the device has Bluetooth and if it is on.
      //Prompts the user to turn it on if it is off
      public void checkBTState()
      {
          // Check device has Bluetooth and that it is turned on
          mBtAdapter=BluetoothAdapter.getDefaultAdapter(); // CHECK THIS OUT THAT IT WORKS!!!
          if(mBtAdapter==null) {
              Toast.makeText(getBaseContext(), "Device does not support Bluetooth", Toast.LENGTH_SHORT).show();
              finish();
          } else {
              if (!mBtAdapter.isEnabled()) {
                  //Prompt user to turn on Bluetooth
                  Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
                  startActivityForResult(enableBtIntent, 1);
              }
          }
      }
  }
  </code></pre>
  
  <p>Here is my stack trace:</p>
  
  <pre class="lang-none prettyprint-override"><code>07-26 16:42:58.492  18894-18894/milind.com.bluetooth_transmission E/AndroidRuntime﹕ FATAL EXCEPTION: main
  Process: milind.com.bluetooth_transmission, PID: 18894
  java.lang.RuntimeException: Unable to resume activity {milind.com.bluetooth_transmission/milind.com.bluetooth_transmission.settings}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ArrayAdapter.clear()' on a null object reference
      at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2980)
      at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3011)
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2394)
      at android.app.ActivityThread.access$900(ActivityThread.java:147)
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1296)
      at android.os.Handler.dispatchMessage(Handler.java:102)
      at android.os.Looper.loop(Looper.java:135)
      at android.app.ActivityThread.main(ActivityThread.java:5254)
      at java.lang.reflect.Method.invoke(Native Method)
      at java.lang.reflect.Method.invoke(Method.java:372)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:898)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)
   Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ArrayAdapter.clear()' on a null object reference
      at milind.com.bluetooth_transmission.settings.onResume(settings.java:53)
      at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1241)
      at android.app.Activity.performResume(Activity.java:6019)
      at     android.app.ActivityThread.performResumeActivity(ActivityThread.java:2969)
  </code></pre>