![](/img/trans.png)
[英]IllegalStateException when click on button in android hello world program
[英]IllegalStateException in android hello world program
我是 android 新手,刚刚开始在 android studio 1.2.2 上编写第一个 hello world 代码并在模拟器 (gennymotion) 上运行,我收到IllegalStateException并且在模拟器中显示
不幸的是,您的应用程序已停止。
java.lang.RuntimeException: Unable to start activity ComponentInfo{jewellers.am.com.amjewellers/jewellers.am.com.amjewellers.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.
这个错误是因为你没有使用AppCompat主题造成的:
您的应用主题必须是:
android:theme="@style/Theme.AppCompat.Light"
清单文件如下所示:
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.AppCompat.Light" >
确保您已在项目中添加AppCompat v7库,并且您必须扩展ActionBarActivity 。
希望这会帮助你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.