android app 在我的设计上崩溃 Nexus 4 Android 5.0 您需要在此活动中使用 Theme.Ap



当我在我的设计 Nexus 4 Android 5.0 上运行我的应用程序时,我创建了一个带有空白活动的 android 项目,其中包含使用片段和 minSdkVersion 10 和 targetSdkVersion 21 创建的空白活动,该应用程序崩溃了,我不知道为什么。

当我从动作栏活动切换到活动时,应用程序

可以工作,但我想使用动作栏活动创建应用程序。

和日志猫给我这个错误 无法启动活动 组件信息{com.rhanem.android.forecast.app/com.rhanem.android.forecast.app.MainActivity}: java.lang.IllegalState异常: 活动已被销毁

她在 logcat 中给我这条消息

Process: com.rhanem.android.forecast.app, PID: 3644
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.rhanem.android.forecast.app/com.rhanem.android.forecast.app.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
            at android.app.ActivityThread.access$800(ActivityThread.java:144)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
     Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
            at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:151)
            at android.support.v7.app.ActionBarActivityDelegateBase.onCreate(ActionBarActivityDelegateBase.java:138)
            at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:123)
            at com.rhanem.android.sunshine.app.MainActivity.onCreate(MainActivity.java:20)
            at android.app.Activity.performCreate(Activity.java:5933)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
            at android.app.ActivityThread.access$800(ActivityThread.java:144)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

请帮助我的

在清单

文件中,为您的活动指定 Theme.AppCompat 主题(或其后代)。 android:theme="Theme.AppCompat"

最新更新