我正在制作一个Android应用程序,当我建立它并运行时,该应用程序停止并显示以下错误,我可以做什么?

问题描述 投票:-2回答:2

我得到的是 RunTimeExpection 当我构建和运行我的代码时。这里是堆栈跟踪。

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

请帮帮我 谢谢你的帮助

android exception runtimeexception
2个回答
0
投票

根据 Nadir Belhaj 答案并作为 MMG 评论:

试试这段代码 styles.xml:

<item name="windowActionBar">false</item> 
<item name="windowNoTitle">true</item>

0
投票

你应该使用工具栏而不是actionbar。所以在你的style.xml中定义一个主题,如下图所示,并在manifest中把它分配给你的应用程序或活动。

styles.xml:

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

或者:

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

manifest :

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

<activity android:name="xxx"  android:theme="@style/AppTheme"/>
© www.soinside.com 2019 - 2024. All rights reserved.