0

I'm trying to create a swipe view as described here http://developer.android.com/training/implementing-navigation/lateral.html

I've created an action bar as per the documentation with final ActionBar actionBar = getActionBar();

but I get the following message

java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.ActionBar.setNavigationMode(int)' on a null object reference

which relates to this line actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

Now i've established that it's likely to do with my theme not having an action bar, see android:theme="@style/Theme.AppCompat.Light.NoActionBar">, so I change my theme to say android:theme="@style/Theme.AppCompat.Light">, but then I get the following message:

java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_SUPPORT_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead

and all the answers on the internet say to change to a non action bar theme, which gives me the first error again. So I'm literally going around in circles. I want to basically have this action bar with tabs as described in the documentation.

Wayneio
  • 3,466
  • 7
  • 42
  • 73
  • Keep the no action bar theme. Make sure to set your toolbar as the support action bar. – chRyNaN Feb 27 '16 at 17:07
  • So I switch to that theme but I get that state exception. I'm creating the toolbar with final ActionBar actionBar = getActionBar(); – Wayneio Feb 27 '16 at 17:37

1 Answers1

0

This theme already has ActionBar:

android:theme="@style/Theme.AppCompat.Light"

And of course, you are trying to use the old ActionBar with AppCompat theme.

So, you will need to use Theme.Holo for that the old ActionBar or if you are using Theme.AppCompat, you need to use it with getSupportActionBar like this:

actionbar = getSupportActionBar();

Check this question: actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS) deprecated

Community
  • 1
  • 1
ʍѳђઽ૯ท
  • 16,646
  • 7
  • 53
  • 108