title: getting null pointer in getSupportActionBar()
body: <p><strong>This is my BaseActivity class that will be extended by other Activities.</strong></p>
  
  <pre><code>import android.graphics.Color;
  import android.graphics.drawable.ColorDrawable;
  import android.os.Build;
  import android.os.Bundle;
  import android.support.v7.app.AppCompatActivity;
  import android.support.v7.widget.SearchView;
  import android.support.v7.widget.Toolbar;
  import android.util.Log;
  import android.view.Menu;
  import android.view.MenuItem;
  import android.view.View;
  import android.widget.ImageButton;
  import android.widget.Toast;
  
  import com.bidhee.jme.R;
  import com.bidhee.jme.controller.bus_and_events.EventBus;
  import com.bidhee.jme.controller.bus_and_events.Events;
  import com.bidhee.jme.model.SearchViewModel;
  import com.bidhee.jme.utils.Metadata;
  import com.bidhee.jme.utils.UtilityMethods;
  
  import butterknife.Bind;
  import butterknife.ButterKnife;
  
  /**
   * Created by ronem on 6/5/16.
   */
  public abstract class BaseActivity extends AppCompatActivity {
      private String TAG = getClass().getSimpleName();
      @Bind(R.id.toolbar)
      Toolbar toolbar;
  
      public SearchView searchView;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(getResourceLayout());
  
          /**
           * Bind {@link ButterKnife}
           */
          ButterKnife.bind(this);
          EventBus.register(this);
  
          /**
           * Setting toolbar in the place of actionbar
           * and enabling the back arrow on it so that use can go back to the previous activity
           */
          setSupportActionBar(toolbar);
  
          assert getSupportActionBar() != null;
          if (getSupportActionBar() != null) {
              this.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
              this.getSupportActionBar().setHomeButtonEnabled(true);
          }
  
  
          /**
           * Loop through all the child's of toolbar
           * and change the attributes value
           */
          if (getActivityId() != 0) {
              if (toolbar != null) {
                  for (int i = 0; i &lt; toolbar.getChildCount(); i++) {
                      View view = toolbar.getChildAt(i);
                      if (view instanceof ImageButton) {
                          ImageButton tv = (ImageButton) view;
                          tv.setColorFilter(Color.WHITE);
                      }
                  }
              }
          }
  
  
          /**
           * If getActivityId matches with the {@link Metadata.DASHBOARD_ID}
           * set actionbar title to empty
           * change the navigation icon to custom icon
           * and background of the action bar to transparent
           *
           */
          if (getActivityId() == Metadata.DASHBOARD_ID) {
              if (getSupportActionBar() != null) {
                  this.getSupportActionBar().setHomeAsUpIndicator(R.mipmap.ic_person_outline_black_24dp);
                  this.getSupportActionBar().setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.transparent)));
              }
          }
  
          if (getSupportActionBar() != null)
              getSupportActionBar().setTitle(getActivityTitle());
  
          /**
           * change the status bar color
           */
          if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.LOLLIPOP) {
              getWindow().setStatusBarColor(getResources().getColor(R.color.colorPrimaryDark));
          }
      }
  
      //returns layout resource
      public abstract int getResourceLayout();
  
      //returns Activity's ID
      public abstract int getActivityId();
  
      //returns Activity Title
      public abstract String getActivityTitle();
  
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
  
          getMenuInflater().inflate(R.menu.menu_japan_money_express, menu);
  
          //setting all menu items tint color to white
          UtilityMethods.setTintColorForMenuItems(menu);
  
          //referencing to search menu item
          MenuItem menuItem = menu.findItem(R.id.action_search);
          searchView = (SearchView) menuItem.getActionView();
          searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
              @Override
              public boolean onQueryTextSubmit(String query) {
                  return false;
              }
  
              @Override
              public boolean onQueryTextChange(String newText) {
  
                  EventBus.post(new Events.SearchViewEvent(new SearchViewModel(newText)));
                  return false;
              }
          });
  
          if (getActivityId() == Metadata.DASHBOARD_ID) {
  
              //show only chat notification icon on toolbar menu and hide rest of the items of toolbar
              showMenu(menu, 0);
  
          } else if (getActivityId() == Metadata.MONEY_TRANSFER_INITIAL_ID) {
  
              //show only search view icon on toolbar menu and hide rest of the items of toolbar
              showMenu(menu, 1);
          } else {
              hideAllMenu(menu);
          }
  
          return super.onCreateOptionsMenu(menu);
  
      }
  
      private void hideAllMenu(Menu menu) {
          for (int i = 0; i &lt; menu.size(); i++) {
              menu.getItem(i).setVisible(false);
              menu.getItem(i).setVisible(false);
          }
      }
  
      private void showMenu(Menu menu, int position) {
          for (int i = 0; i &lt; menu.size(); i++) {
              if (position == i) {
                  menu.getItem(i).setVisible(true);
              } else {
                  menu.getItem(i).setVisible(false);
              }
          }
      }
  
      /**
       * Overriding the onOptionItemSelected so that we can access the actions of the actionbar
       *
       * @param item
       * @return
       */
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          switch (item.getItemId()) {
              case android.R.id.home:
                  if (getActivityId() == Metadata.DASHBOARD_ID) {
                      Toast.makeText(getApplicationContext(), "user info under constrction", Toast.LENGTH_SHORT).show();
                  } else {
                      this.finish();
                  }
  
                  break;
          }
          return super.onOptionsItemSelected(item);
      }
  
      @Override
      public void onBackPressed() {
          super.onBackPressed();
          overridePendingTransition(R.anim.zoom_in_from_top_left_to_bottom_right, R.anim.slide_down_dialog);
      }
  
      @Override
      protected void onDestroy() {
          super.onDestroy();
          /**
           * must unbind the ButterKnife on Destroy
           */
          ButterKnife.unbind(this);
          EventBus.unregister(this);
  
      }
  }
  </code></pre>
  
  <p>And there are more than 3 activities that will extends this base class activity. one of them is this.</p>
  
  <p><strong>CheckRateActivity.java</strong></p>
  
  <pre><code>import android.content.Intent;
  import android.os.Bundle;
  import android.util.Log;
  import android.view.View;
  import android.widget.ImageView;
  import android.widget.LinearLayout;
  import android.widget.TextView;
  
  import com.bidhee.jme.R;
  import com.bidhee.jme.controller.bus_and_events.Events;
  import com.bidhee.jme.model.CountryModel;
  import com.squareup.otto.Subscribe;
  
  import butterknife.Bind;
  import butterknife.OnClick;
  
  /**
   * Created by ronem on 6/13/16.
   */
  public class CheckRateActivity extends BaseActivity {
      private String TAG = getClass().getSimpleName();
  
      @Bind(R.id.sendingFromLayout)
      LinearLayout sendingFromLayout;
      @Bind(R.id.sendingtoLayout)
      LinearLayout sendingToLayout;
  
      CountryModel country;
      ImageView fromCountryFlag, toCountryFlag;
      TextView fromCountryTitle, toCountryTitle;
      View arrowDownTo;
  
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          fromCountryFlag = (ImageView) sendingFromLayout.findViewById(R.id.row_image);
          fromCountryTitle = (TextView) sendingFromLayout.findViewById(R.id.row_title);
  
          fromCountryFlag.setImageResource(R.drawable.jamaica);
          fromCountryTitle.setText("Jamaica");
  
          toCountryFlag = (ImageView) sendingToLayout.findViewById(R.id.row_image);
          toCountryTitle = (TextView) sendingToLayout.findViewById(R.id.row_title);
          arrowDownTo = (View) sendingToLayout.findViewById(R.id.arrow_down_view);
          arrowDownTo.setVisibility(View.VISIBLE);
  
      }
  
      @Override
      public int getResourceLayout() {
          return R.layout.check_rate_layout;
      }
  
      @Override
      public int getActivityId() {
          return 0;
      }
  
      @Override
      public String getActivityTitle() {
          return "Check rates";
      }
  
      @OnClick(R.id.sendingtoLayout)
      public void onSendinToLayoutClicked() {
  
          Intent intent = new Intent(CheckRateActivity.this, SelectCountryListActivity.class);
          startActivity(intent);
      }
  
  
      @Subscribe
      public void getCountry(Events.CountryModelEvent _country) {
          if (_country != null) {
              Log.d(TAG, _country.getCountryModel().toString());
              country = _country.getCountryModel();
  
              toCountryFlag.setImageResource(country.getCountryIcon());
              toCountryTitle.setText(country.getCountryName());
  
              Intent intent = new Intent(CheckRateActivity.this, MakeTransferActivity.class);
  //            Bundle bundle = new Bundle();
  //            bundle.putString(Metadata.COUNTRY_ID, c.getId());
  //            bundle.putString(Metadata.COUNTRY_NAME, c.getCountryName());
  //            bundle.putInt(Metadata.COUNTRY_FLAG, c.getCountryIcon());
  //
  //            intent.putExtras(bundle);
  
              Bundle box = new Bundle();
              box.putParcelable("country", country);
              intent.putExtras(box);
              startActivity(intent);
          }
      }
  
  
  }
  </code></pre>
  
  <p>This is my AndroidManifest.xml file content</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.bidhee.jme"&gt;
  
      &lt;supports-screens
          android:anyDensity="true"
          android:largeScreens="true"
          android:normalScreens="true"
          android:smallScreens="true"
          android:xlargeScreens="true" /&gt;
  
      &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;
      &lt;uses-permission android:name="android.permission.GET_ACCOUNTS" /&gt;
      &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
      &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
      &lt;uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /&gt;
  
      &lt;application
          android:name=".controller.AppController"
          android:allowBackup="true"
          android:icon="@mipmap/ic_launcher"
          android:label="@string/app_name"
          android:largeHeap="true"
          android:launchMode="singleTask"
          android:supportsRtl="true"
          android:theme="@style/AppTheme"&gt;
          &lt;activity
              android:name=".views.activities.JapanMoneyExpress"
              android:label="@string/app_name"
              android:theme="@style/AppTheme.NoActionBar"&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;activity
              android:name=".views.activities.Dashboard"
              android:label="@string/dashboard"
              android:screenOrientation="portrait" /&gt;
  
          &lt;activity
              android:name=".views.activities.RegisterNewAccount"
              android:screenOrientation="portrait" /&gt;
          &lt;activity
              android:name=".views.activities.CheckRateActivity"
              android:screenOrientation="portrait" /&gt;
          &lt;activity
              android:name=".views.activities.SelectCountryListActivity"
              android:screenOrientation="portrait" /&gt;
          &lt;activity
              android:name=".views.activities.MakeTransferActivity"
              android:screenOrientation="portrait" /&gt;
  
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p><strong>These are styles</strong></p>
  
  <pre><code>&lt;!-- Base application theme. --&gt;
  &lt;style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"&gt;
      &lt;!-- Customize your theme here. --&gt;
      &lt;item name="colorPrimary"&gt;@color/colorPrimary&lt;/item&gt;
      &lt;item name="colorPrimaryDark"&gt;@color/colorPrimaryDark&lt;/item&gt;
      &lt;item name="android:windowBackground"&gt;@color/white&lt;/item&gt;
      &lt;!--&lt;item name="colorControlHighlight"&gt;@color/white&lt;/item&gt;--&gt;
      &lt;item name="colorAccent"&gt;@color/colorAccent&lt;/item&gt;
  &lt;/style&gt;
  
  &lt;style name="AppTheme.NoActionBar"&gt;
      &lt;item name="windowActionBar"&gt;false&lt;/item&gt;
      &lt;item name="windowNoTitle"&gt;true&lt;/item&gt;
  &lt;/style&gt;
  </code></pre>
  
  <p>App run smooth for most of the time but some times I get the NullpointerException in getSupportActionBar(). so I used these piece of code as suggested in StackOverflow.</p>
  
  <pre><code>assert getSupportActionBar() != null;
          if (getSupportActionBar() != null) {
              this.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
              this.getSupportActionBar().setHomeButtonEnabled(true);
          }
  </code></pre>
  
  <p>now app runs but some time I cant see any title and back arrow home key in toolbar.
  I am stuck with this for more than 1 day.</p>