![](/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.