-5

I am trying to create an navigation drawer in my app for the first time. I made a new project and chose the navigation drawer activity as the main activity. I am just using that as an example. Everything seems to be done, but when I run the app, it runs into this exact error

Process: com.eduard.butka.songs, PID: 14469

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.eduard.butka.songs/com.eduard.butka.songs.MainActivity}: 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.
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2763)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2824)
        at android.app.ActivityThread.-wrap12(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1546)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6351)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:896)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:786)
     Caused by: 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.
        at android.support.v7.app.AppCompatDelegateImplV9.setSupportActionBar(AppCompatDelegateImplV9.java:201)
        at android.support.v7.app.AppCompatActivity.setSupportActionBar(AppCompatActivity.java:129)
        at com.eduard.butka.songs.MainActivity.onCreate(MainActivity.java:79)
        at android.app.Activity.performCreate(Activity.java:6775)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2716)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2824) 
        at android.app.ActivityThread.-wrap12(ActivityThread.java) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1546) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:154) 
        at android.app.ActivityThread.main(ActivityThread.java:6351) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:896) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:786) 

I looked at some other answers, but I didnt find anything, and I am very confused because I copied most of the things from the example android studio gives you, but my app crashes, while the example runs just fine. Here is my onCreate()

@Override
protected void onCreate(Bundle savedInstanceState)
 {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);            //this is line 79, where the app crashes

    DrawerLayout drawer = (DrawerLayout)findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.addDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView)findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
 }

and here is my styles.xml

<resources>

<style name="AppTheme" parent="AppTheme.Base"></style>
<!-- Base application theme. -->
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="android:windowContentTransitions">true</item>

    <item name = "android:windowEnterTransition">@android:transition/fade</item>
    <item name = "android:windowExitAnimation">@android:transition/fade</item>

    <item name = "android:windowAllowEnterTransitionOverlap">true</item>
    <item name = "android:windowAllowReturnTransitionOverlap">true</item>
    <item name = "android:windowSharedElementEnterTransition">@android:transition/move</item>
    <item name = "android:windowSharedElementExitTransition">@android:transition/move</item>

    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>

    <item name="android:textColorHint">@color/colorHint</item>

    <item name="android:orientation">vertical</item>

</style>

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

<style name ="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar"/>
<style name ="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Dark"/>

<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
    <item name="android:windowBackground">@drawable/splash</item>
</style>
</resources>

and activity_main.xml

 <?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start"
>
<include
    layout="@layout/action_bar_main"
    android:layout_height="match_parent"
    android:layout_width="match_parent"/>
<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    app:menu="@menu/activity_main_drawer"
    />
 </android.support.v4.widget.DrawerLayout>

I looked through everything, and compared everything to the AndroidStudio example, but could not find anything.

Kirill Simonov
  • 8,257
  • 3
  • 18
  • 42
Eddie
  • 63
  • 2
  • 2
  • 9

1 Answers1

4

Use this inside your application tag in manifest or inside MainActivity tag.

android:theme="@style/AppTheme.NoActionBar"

theanilpaudel
  • 3,348
  • 8
  • 39
  • 67