title: Method Invocation actionbar.somemethod() may produce java null pointer exception
body: <p>In my application I want to customize my actionbar but when I try to do the same Java NullpointerException is thrown by my application.Also in my application I am using navigation drawer in which I have to add fragments to main activity so in some of my fragment I not want to show action bar but when I call actionbar.hide() it throws JNE. here is the code :</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  private static String TAG = MainActivity.class.getSimpleName();
  Boolean flag = false;
  ListView mDrawerList;
  RelativeLayout mDrawerPane;
  private DrawerLayout mDrawerLayout;
  public static FragmentManager fragmentManager;
  ArrayList&lt;NavItem&gt; mNavItems = new ArrayList&lt;NavItem&gt;();
  static GoogleMap mMap;
  FragmentTransaction fragmentTransaction;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      ActionBar actionBar = getSupportActionBar();
      actionBar.hide();
      if (findViewById(R.id.mainContent) != null) {
  
          if (savedInstanceState != null) {
              return;
          }
          fragmentManager = getFragmentManager();
          HomeFragment homefragment = new HomeFragment();
          fragmentManager.beginTransaction().add(R.id.mainContent, homefragment).commit();
          flag = true;
      }
      mNavItems.add(new NavItem("Profile",R.drawable.ace));
      mNavItems.add(new NavItem("Book A Truck",R.drawable.ace));
      mNavItems.add(new NavItem("My Bookings",R.drawable.ace));
      mNavItems.add(new NavItem("Farecards",R.drawable.ace));
      mNavItems.add(new NavItem("Call Support",R.drawable.ace));
      mNavItems.add(new NavItem("About",R.drawable.ace));
  
      // DrawerLayout
      mDrawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
  
      // Populate the Navigtion Drawer with options
      mDrawerPane = (RelativeLayout) findViewById(R.id.drawerPane);
      mDrawerList = (ListView) findViewById(R.id.navList);
      DrawerListAdapter adapter = new DrawerListAdapter(this, mNavItems);
      mDrawerList.setAdapter(adapter);
  
      // Drawer Item click listeners
      mDrawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
              if (position == 4){
                  String number = "tel:9643173925";
                  Intent telephonecall = new Intent(Intent.ACTION_CALL,Uri.parse(number));
                  startActivity(telephonecall);
                  mDrawerLayout.closeDrawer(mDrawerPane);
              } else if (position == 1 &amp;&amp; flag) {
                  mDrawerLayout.closeDrawer(mDrawerPane);
              } else {
                  selectItemFromDrawer(position);
              }
          }
      });
  }
  
  private void selectItemFromDrawer(int position) {
      Fragment fragment = new HomeFragment();
      Class fragmentClass = null;
      switch (position) {
          case 0:
              fragmentClass = ProfileFragment.class;
              flag = false;
              break;
          case 1:
              fragmentClass = HomeFragment.class;
              flag = true;
              break;
          case 2:
              fragmentClass = MybookingFragment.class;
              flag =false;
              break;
          case 3:
              fragmentClass = FarecardFragment.class;
              flag = false;
              break;
          case 5:
              fragmentClass = AboutFragment.class;
              flag = false;
              break;
          default:
              fragmentClass = HomeFragment.class;
              flag = true;
              break;
      }
      try {
          fragment = (Fragment) fragmentClass.newInstance();
      } catch (Exception e) {
          e.printStackTrace();
      }
      String backstackname = fragmentClass.getName();
      FragmentManager fragmentManager = getFragmentManager();
      fragmentManager.beginTransaction().replace(R.id.mainContent, fragment).addToBackStack(null).commit();
      mDrawerLayout.closeDrawer(mDrawerPane);
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.menu_main, menu);
      return true;
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      // Handle action bar item clicks here. The action bar will
      // automatically handle clicks on the Home/Up button, so long
      // as you specify a parent activity in AndroidManifest.xml.
      int id = item.getItemId();
  
      //noinspection SimplifiableIfStatement
      if (id == R.id.action_settings) {
          return true;
      }
  
      return super.onOptionsItemSelected(item);
  }
  </code></pre>
  
  <p>}</p>
  
  <p>And my Manifest file code is here :</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  </code></pre>
  
  <p></p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.INTERNET" /&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;
  &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
  &lt;uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /&gt;
  &lt;uses-permission android:name="android.permission.WAKE_LOCK" /&gt;
  &lt;uses-permission android:name="android.permission.WAKE_LOCK" /&gt;
  &lt;uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /&gt;
  
  &lt;permission
      android:name="in.moovo.route.permission.C2D_MESSAGE"
      android:protectionLevel="signature" /&gt;
  
  &lt;uses-permission android:name="in.moovo.route.permission.C2D_MESSAGE" /&gt;
  &lt;uses-permission android:name="android.permission.CALL_PHONE" /&gt;
  &lt;uses-permission android:name="android.permission.READ_PHONE_STATE" /&gt;
  
  &lt;uses-feature
      android:glEsVersion="0x00020000"
      android:required="true" /&gt;
  
  &lt;application
      android:allowBackup="true"
      android:icon="@mipmap/ic_launcher"
      android:label="@string/app_name"
      android:theme="@style/AppTheme" &gt;
      &lt;receiver
          android:name="com.google.android.gms.gcm.GcmReceiver"
          android:exported="true"
          android:permission="com.google.android.c2dm.permission.SEND" &gt;
          &lt;intent-filter&gt;
              &lt;action android:name="com.google.android.c2dm.intent.RECEIVE" /&gt;
  
              &lt;category android:name="com.example.gcm" /&gt;
          &lt;/intent-filter&gt;
      &lt;/receiver&gt;
      &lt;!-- &lt;service --&gt;
      &lt;!-- android:name="in.moovo.MyGcmListenerService" --&gt;
      &lt;!-- android:exported="false" &gt; --&gt;
      &lt;!-- &lt;intent-filter&gt; --&gt;
      &lt;!-- &lt;action android:name="com.google.android.c2dm.intent.RECEIVE" /&gt; --&gt;
      &lt;!-- &lt;/intent-filter&gt; --&gt;
      &lt;!-- &lt;/service&gt; --&gt;
      &lt;!-- &lt;service --&gt;
      &lt;!-- android:name="in.moovo.MyInstanceIDListenerService" --&gt;
      &lt;!-- android:exported="false"&gt; --&gt;
      &lt;!-- &lt;intent-filter&gt; --&gt;
      &lt;!-- &lt;action android:name="com.google.android.gms.iid.InstanceID"/&gt; --&gt;
      &lt;!-- &lt;/intent-filter&gt; --&gt;
      &lt;!-- &lt;/service&gt; --&gt;
      &lt;meta-data
          android:name="com.google.android.gms.version"
          android:value="@integer/google_play_services_version" /&gt;
      &lt;meta-data
          android:name="com.google.android.maps.v2.API_KEY"
          android:value="@string/google_maps_key" /&gt;
  
      &lt;activity
          android:name=".Googlemap"
          android:label="@string/title_activity_googlemap" &gt;
  
          &lt;!-- &lt;intent-filter&gt; --&gt;
          &lt;!-- &lt;action android:name="android.intent.action.MAIN" /&gt; --&gt;
  
  
          &lt;!-- &lt;category android:name="android.intent.category.LAUNCHER" /&gt; --&gt;
          &lt;!-- &lt;/intent-filter&gt; --&gt;
      &lt;/activity&gt;
      &lt;activity
          android:name=".Confirm"
          android:label="@string/title_activity_confirm" &gt;
      &lt;/activity&gt;
      &lt;activity
          android:name=".MainActivity"
          android:label="@string/title_activity_main" &gt;
      &lt;/activity&gt;
      &lt;activity
          android:name=".Moovo"
          android:label="@string/title_activity_moovo" &gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
  
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
  &lt;/application&gt;
  </code></pre>
  
  <p></p>
  
  <p>Erro log give this :</p>
  
  <pre><code>java.lang.RuntimeException: Unable to start activity ComponentInfo{in.moovo.route/in.moovo.route.Moovo}: java.lang.NullPointerException
          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2198)
          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2257)
          at android.app.ActivityThread.access$800(ActivityThread.java:139)
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
          at android.os.Handler.dispatchMessage(Handler.java:102)
          at android.os.Looper.loop(Looper.java:136)
          at android.app.ActivityThread.main(ActivityThread.java:5086)
          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:785)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
          at dalvik.system.NativeStart.main(Native Method)
   Caused by: java.lang.NullPointerException
          at in.moovo.route.Moovo.onCreate(Moovo.java:41)
          at android.app.Activity.performCreate(Activity.java:5248)
          at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1110)
          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2162)
  </code></pre>
  
  <p>            </p>
  
  <p>My style.xml file :</p>
  
  <pre><code>resources&gt;
  
  &lt;!-- Base application theme. --&gt;
  &lt;style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"&gt;
      &lt;!-- Customize your theme here. --&gt;
      &lt;!--Action bar style--&gt;
      &lt;item name="android:actionBarStyle"&gt;@style/MyActionBar&lt;/item&gt;
      &lt;!-- Support library compatibility --&gt;
      &lt;item name="actionBarStyle"&gt;@style/MyActionBar&lt;/item&gt;
  &lt;/style&gt;
  &lt;!-- ActionBar styles --&gt;
  &lt;style name="MyActionBar"
      parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse"&gt;
      &lt;item name="android:background"&gt;@drawable/actionbartheme&lt;/item&gt;
  
      &lt;!-- Support library compatibility --&gt;
      &lt;item name="background"&gt;@drawable/actionbartheme&lt;/item&gt;
      &lt;item name="height"&gt;50dp&lt;/item&gt;
  &lt;/style&gt;
  &lt;style name="MyTheme" parent="@android:style/Theme.Dialog"&gt;
      &lt;item name="android:alertDialogStyle"&gt;@style/CustomAlertDialogStyle&lt;/item&gt;
      &lt;item name="android:textColorPrimary"&gt;#a91c44&lt;/item&gt;
  &lt;/style&gt;
  &lt;style name="CustomAlertDialogStyle"&gt;
      &lt;item name="android:bottomBright"&gt;#a91c44&lt;/item&gt;
  &lt;/style&gt;
  </code></pre>
  
  <p></p>