-2

I am getting RunTimeExpection when I build and run my code. Here the stacktrace:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.besecure/com.example.besecure.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:2817)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2895)
    at android.app.ActivityThread.-wrap11(Unknown Source:0)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1616)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:176)
    at android.app.ActivityThread.main(ActivityThread.java:6651)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:824)
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 androidx.appcompat.app.AppCompatDelegateImpl.setSupportActionBar(AppCompatDelegateImpl.java:421)
    at androidx.appcompat.app.AppCompatActivity.setSupportActionBar(AppCompatActivity.java:150)
    at com.example.besecure.MainActivity.onCreate(MainActivity.java:29)
    at android.app.Activity.performCreate(Activity.java:7088)
    at android.app.Activity.performCreate(Activity.java:7079)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1215)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
    ... 9 more

Please, help me on this. Thanks

Lino
  • 4,443
  • 3
  • 20
  • 35
  • Set windowActionBar to false in your theme – MMG May 10 '20 at 04:49
  • Does this answer your question? [This Activity already has an action bar supplied by the window decor](https://stackoverflow.com/questions/26515058/this-activity-already-has-an-action-bar-supplied-by-the-window-decor) – ADM May 10 '20 at 05:03
  • Does this answer your question? [Do not request Window.FEATURE\_SUPPORT\_ACTION\_BAR](https://stackoverflow.com/questions/41586347/do-not-request-window-feature-support-action-bar) – Ali.DM May 10 '20 at 05:13

2 Answers2

0

According to Nadir Belhaj answers and as MMG comments,

Try this code in styles.xml:

<item name="windowActionBar">false</item> 
<item name="windowNoTitle">true</item>
Milad Bahmanabadi
  • 1,047
  • 11
  • 23
0

You should use toolbar instead of actionbar. So in your styles.xml define a theme like below and assign it to your application or activity in the manifest:

styles.xml:

<style name="AppTheme" parent="Theme.AppCompat.Light">
    <item name="windowActionBar">false</item>
</style>

Or:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
</style>

manifest :

<application
   ....
    android:icon="@drawable/xxx"
    android:theme="@style/AppTheme">
</application>

or

<activity android:name="xxx"  android:theme="@style/AppTheme"/>
Ali.DM
  • 248
  • 5
  • 10