Android应用在模拟器启动时崩溃

时间:2014-07-06 13:46:01

标签: java android android-emulator crash android-logcat

我试图制作一个Android应用,当我尝试在模拟器中测试它时,错误弹出说,不幸的是,komok已停止(komok是我的应用程序)我已经使用Logcat尝试了解一切,但由于我不熟悉Java开发,我似乎无法看到我需要修复的内容,如果有人可以看看这个和告诉我我做错了什么,我将非常感激。

这是Logcat:

07-06 09:35:05.204    4934-4934/p110.uk.helloworld E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: p110.uk.helloworld, PID: 4934
java.lang.RuntimeException: Unable to start activity ComponentInfo{p110.uk.helloworld/p110.uk.helloworld.MyActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2255)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2317)
        at android.app.ActivityThread.access$800(ActivityThread.java:143)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1258)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5070)
        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:836)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:631)
 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:108)
        at android.support.v7.app.ActionBarActivityDelegateICS.onCreate(ActionBarActivityDelegateICS.java:57)
        at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:98)
        at p110.uk.helloworld.MyActivity.onCreate(MyActivity.java:22)
        at android.app.Activity.performCreate(Activity.java:5720)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1102)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2208)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2317)
        at android.app.ActivityThread.access$800(ActivityThread.java:143)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1258)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5070)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)

如果有人能告诉我问题是什么以及如何解决这个问题会很棒,我认为问题是:

Unable to start activity ComponentInfo{p110.uk.helloworld/p110.uk.helloworld.MyActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

但我仍然不知道如何解决这个问题,所以如果有人这样做,请帮助我,谢谢!

2 个答案:

答案 0 :(得分:3)

1.您的项目需要包含Android.AppCompact.v7

取决于你的使用

Android Studio:文件 - >项目结构 - > Dependenices - >按加号和Libaray 并选择App Compact

Eclipse - 转到构建路径 - >图书馆 - >添加外部Jar并从SDK

添加AppCompat Jar 希望它有所帮助。

2.如果您的Activity扩展ActionBarActivity,则将其更改为FragmentActivity

答案 1 :(得分:0)

问题在于:

Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

或者:

  • 将MyActivity扩展为活动,而不是ActionBarActivity(或其他 支持班)。
  • 将AppCompat.v7导入您的项目。您可能需要先下载支持库。
相关问题