title: NullPointerException on Intent Extras
body: <p>I am trying to use <code>Intent</code> to call a new <code>Activity</code> from <code>MainActivity</code>. And I am trying to pass some data through <code>Intent Extras</code>. Below is my code for calling new <code>Activity</code>.</p>
  
  <pre><code>public void tabSelector2(View v) {
      switch (v.getId()) {
          case R.id.veg_tab:
              currentDB = "veg";
              break;
          case R.id.meat_tab :
              currentDB = "meat";
              break;
          default:
              break;
      }
  
      Intent tabSelect = new Intent(this, TabSelector.class);
      tabSelect.putExtra("db_passed", currentDB);
      startActivity(tabSelect);
  }
  </code></pre>
  
  <p>Inside <code>onCreate</code> for <code>Activity2</code> I try to use the variable <code>currentDB</code> that I passed. The variable is passed correctly. I printed the value using <code>System.out.println()</code> and <code>logcat</code> produces correct output. But I am getting a <code>NullPointerException</code> when I am trying to use the value. Code snippet for <code>onCreate</code> is below :</p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
      setTheme(android.R.style.Theme_Holo); // (for Android Built In Theme)
  
      mydb = new DBHelper(this);
  
      Bundle extras = getIntent().getExtras();
      if (extras != null) {
          currentDB = extras.getString("db_passed");
      }
  
      System.out.println(currentDB);    // Printing here, correct value
  
      currentList2 = mydb.getAllItemsAsCollection(currentDB);    // Works Perfectly
      itemAdder2.setDbName(currentDB);    // Produces an error :(
      itemAdder2.updateData2(currentList2);
  
      switch (currentDB) {
          case "veg" :
              setContentView(R.layout.vegetable);
              currentListView = (ListView) findViewById(R.id.veg_list);
              break;
          case "meat" :
              setContentView(R.layout.meat_drawer);
              currentListView = (ListView) findViewById(R.id.meat_list);
              break;
          default:
              break;
      }
  
      currentListView.setAdapter(itemAdder2);
  
      this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
  }
  </code></pre>
  
  <p>The corresponding <code>setDBName</code> method is as simple as it gets.</p>
  
  <pre><code>public void setDbName(String dbName){
      this.dbName = dbName;
  }
  </code></pre>
  
  <p>I am getting the following error while runtime...</p>
  
  <pre><code>08-02 13:20:23.757    2641-2701/com.example.user.reggaeshark I/OpenGLRenderer? Initialized EGL, version 1.4
  08-02 13:20:23.838    2641-2701/com.example.user.reggaeshark D/OpenGLRenderer? Enabling debug mode 0
  08-02 13:20:24.150    2641-2701/com.example.user.reggaeshark V/RenderScript? Application requested CPU execution
  08-02 13:20:24.163    2641-2701/com.example.user.reggaeshark V/RenderScript? 0xb857f848 Launching thread(s), CPUs 4
  08-02 13:20:25.817    2641-2659/com.example.user.reggaeshark W/art? Suspending all threads took: 8.192ms
  08-02 13:20:25.843    2641-2641/com.example.user.reggaeshark I/System.out? meat
  08-02 13:20:25.861    2641-2641/com.example.user.reggaeshark D/AndroidRuntime? Shutting down VM
  08-02 13:20:25.868    2641-2641/com.example.user.reggaeshark E/AndroidRuntime? FATAL EXCEPTION: main
  Process: com.example.user.reggaeshark, PID: 2641
  java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.user.reggaeshark/com.example.user.reggaeshark.TabSelector}: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.example.user.reggaeshark.ListViewAdapter.setDbName(java.lang.String)' on a null object reference
          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2314)
          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2388)
          at android.app.ActivityThread.access$800(ActivityThread.java:148)
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1292)
          at android.os.Handler.dispatchMessage(Handler.java:102)
          at android.os.Looper.loop(Looper.java:135)
          at android.app.ActivityThread.main(ActivityThread.java:5312)
          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:901)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696)
   Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.example.user.reggaeshark.ListViewAdapter.setDbName(java.lang.String)' on a null object reference
          at com.example.user.reggaeshark.TabSelector.onCreate(TabSelector.java:43)
          at android.app.Activity.performCreate(Activity.java:5953)
          at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1128)
          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2267)
          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2388)
          at android.app.ActivityThread.access$800(ActivityThread.java:148)
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1292)
          at android.os.Handler.dispatchMessage(Handler.java:102)
          at android.os.Looper.loop(Looper.java:135)
          at android.app.ActivityThread.main(ActivityThread.java:5312)
          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:901)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696)
  </code></pre>
  
  <p>Please help. Let me know if you guys need anything extra.</p>