java.lang.IllegalStateException: You need to use a Theme.AppCompat theme

來源:互聯網
上載者:User

標籤:

配置:

中設定theme為

    <application        android:allowBackup="true"        android:icon="@mipmap/ic_launcher"        android:theme="@android:style/Theme.Light.NoTitleBar"        android:label="@string/app_name"        >

報錯資訊:

09-20 10:31:58.185    1392-1392/? E/AndroidRuntime﹕ FATAL EXCEPTION: main    Process: networkimageviewer.com.myapplication, PID: 1392    java.lang.RuntimeException: Unable to start activity ComponentInfo{networkimageviewer.com.myapplication/networkimageviewer.com.myapplication.WelcomeActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2192)            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2241)            at android.app.ActivityThread.access$800(ActivityThread.java:141)            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1204)            at android.os.Handler.dispatchMessage(Handler.java:102)            at android.os.Looper.loop(Looper.java:136)            at android.app.ActivityThread.main(ActivityThread.java:5049)            at java.lang.reflect.Method.invokeNative(Native Method)            at java.lang.reflect.Method.invoke(Method.java:515)            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)            at dalvik.system.NativeStart.main(Native Method)     Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.            at android.support.v7.app.AppCompatDelegateImplV7.createSubDecor(AppCompatDelegateImplV7.java:309)            at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:278)            at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:252)            at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)            at networkimageviewer.com.myapplication.WelcomeActivity.onCreate(WelcomeActivity.java:22)            at android.app.Activity.performCreate(Activity.java:5249)            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2156)            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2241)            at android.app.ActivityThread.access$800(ActivityThread.java:141)            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1204)            at android.os.Handler.dispatchMessage(Handler.java:102)            at android.os.Looper.loop(Looper.java:136)            at android.app.ActivityThread.main(ActivityThread.java:5049)            at java.lang.reflect.Method.invokeNative(Native Method)            at java.lang.reflect.Method.invoke(Method.java:515)            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)            at dalvik.system.NativeStart.main(Native Method)

解決辦法:
To simply add ActionBar Compat your activity or application should use @style/Theme.AppCompat theme in AndroidManifest.xml like this:

    <application        android:allowBackup="true"        android:icon="@mipmap/ic_launcher"        android:theme="@style/Theme.AppCompat.Light.NoActionBar"        android:label="@string/app_name"        >

 

http://stackoverflow.com/questions/18063395/actionbarcompat-java-lang-illegalstateexception-you-need-to-use-a-theme-appcom

java.lang.IllegalStateException: You need to use a Theme.AppCompat theme

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.