title: Getting crash in Android on onResume() in my activity - Why?
body: <p>The error is:</p>
  
  <p><strong>Unable to resume activity: java.lang.NullPointerException</strong></p>
  
  <p>Here is the stack trace:</p>
  
  <pre><code>0 java.lang.RuntimeException: Unable to resume activity {com.sortitapps.movies/com.sortitapps.movies.SettingsActivity}: java.lang.NullPointerException
  1 at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2944)
  2 at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2973)
  3 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2408)
  4 at android.app.ActivityThread.access$600(ActivityThread.java:165)
  5 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1373)
  6 at android.os.Handler.dispatchMessage(Handler.java:107)
  7 at android.os.Looper.loop(Looper.java:194)
  8 at android.app.ActivityThread.main(ActivityThread.java:5391)
  9 at java.lang.reflect.Method.invokeNative(Native Method)
  10 at java.lang.reflect.Method.invoke(Method.java:525)
  11 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
  12 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
  13 at dalvik.system.NativeStart.main(Native Method)
  14 Caused by: java.lang.NullPointerException
  15 at com.sortitapps.movies.SettingsActivity.onResume(SettingsActivity.java:149)
  16 at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1259)
  17 at android.app.Activity.performResume(Activity.java:5200)
  18 at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2931)
  </code></pre>
  
  <p>And here is the code. <strong>Line 149 is adapter.notifyDataSetChanged();</strong>:</p>
  
  <pre><code>@Override
  public void onResume() 
  {
      super.onResume();  // Always call the superclass method first
  
      SharedPreferences settings = getSharedPreferences("prefs", 0);
  
      int numberDesktop = settings.getInt("desktop", 0);
      Log.i("Desktop purchased:", String.valueOf(numberDesktop));
  
      int numberScans = settings.getInt("scanning", 0);
      Log.i("Number of scans:", String.valueOf(numberScans));
  
      if (settingsitems.contains("Unlock Desktop Apps") &amp;&amp;
              numberDesktop == 2)
      {
          settingsitems.remove("Unlock Desktop Apps");
      }
  
      String freeapp = getResources().getString(R.string.free_app);
  
      if (settingsitems.contains("Unlock Premium Features") &amp;&amp;
              freeapp.equals("Yes") &amp;&amp; 
              numberScans &gt; 10)
      {
          settingsitems.remove("Unlock Premium Features");
      }
  
      adapter.notifyDataSetChanged();
  }
  </code></pre>
  
  <p>Do I need to initialize the adapter again when coming resuming?</p>