我正在制作一个Android应用程序,当我构建它并运行时,该应用程序停止并显示以下错误,那么我该怎么办?

我正在制作一个Android应用程序,当我构建它并运行时,该应用程序停止并显示以下错误,那么我该怎么办?,android,exception,runtimeexception,Android,Exception,Runtimeexception,当我构建和运行代码时,我得到了RunTimeExpection。这里是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 suppli

当我构建和运行代码时,我得到了RunTimeExpection。这里是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
请帮我做这个。谢谢

根据回答和评论

在styles.xml中尝试以下代码:

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

您应该使用工具栏而不是actionbar。因此,在styles.xml中定义如下主题,并将其分配给清单中的应用程序或活动:

styles.xml:

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

舱单:

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


在主题中将windowActionBar设置为false是否回答您的问题?这回答了你的问题吗?
<application
   ....
    android:icon="@drawable/xxx"
    android:theme="@style/AppTheme">
</application>
<activity android:name="xxx"  android:theme="@style/AppTheme"/>