I'm following the tutorial https://www.youtube.com/watch?v=VVahIc8yENk and I'm getting the error
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.ActionBar.setNavigationMode(int)' on a null object reference
I'm using Android Studio to write this program and I have tried from API 11 to 21 and none of them work.
public class Tabtest extends FragmentActivity implements ActionBar.TabListener {
ActionBar actionBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tab_test);
actionBar=getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
ActionBar.Tab tab1=actionBar.newTab();
tab1.setText("tab1");
tab1.setTabListener(this);
ActionBar.Tab tab2=actionBar.newTab();
tab2.setText("tab2");
tab2.setTabListener(this);
ActionBar.Tab tab3=actionBar.newTab();
tab3.setText("tab3");
tab3.setTabListener(this);
ActionBar.Tab tab4=actionBar.newTab();
tab4.setText("tab4");
tab4.setTabListener(this);
actionBar.addTab(tab1);
actionBar.addTab(tab2);
actionBar.addTab(tab3);
actionBar.addTab(tab4);
}
@Override
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
Log.d("VIVZ", "onTabReselected at "+" position "+tab.getPosition()+" name "+tab.getText());
}
@Override
public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) {
Log.d("VIVZ", "onTabReselected at "+" position "+tab.getPosition()+" name "+tab.getText());
}
@Override
public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) {
Log.d("VIVZ", "onTabReselected at "+" position "+tab.getPosition()+" name "+tab.getText());
}
}