简体   繁体   中英

Theme.AppCompat theme stacktrace. No solution found in my case

I try to show a dialog in my Activity and I get this error : "You need to use a Theme.AppCompat theme"

There are lots of question/answers about this, but I don't get it in my situation: Can someone help me ? I know it has something to do with the app theme, but I think this is ok in my situation. Can please someone take a look:

Error:

java.lang.RuntimeException: 

    Unable to start activity ComponentInfo{chronicbrowser_maps_en/chronicbrowser.ChronicBrowser}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
                                                         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
                                                         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
                                                         at android.app.ActivityThread.-wrap12(ActivityThread.java)
                                                         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
                                                         at android.os.Handler.dispatchMessage(Handler.java:102)
                                                         at android.os.Looper.loop(Looper.java:154)
                                                         at android.app.ActivityThread.main(ActivityThread.java:6077)
                                                         at java.lang.reflect.Method.invoke(Native Method)
                                                         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
                                                      Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
                                                         at android.support.v7.app.AppCompatDelegateImplV9.createSubDecor(AppCompatDelegateImplV9.java:359)
                                                         at android.support.v7.app.AppCompatDelegateImplV9.ensureSubDecor(AppCompatDelegateImplV9.java:328)
                                                         at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:289)
                                                         at android.support.v7.app.AppCompatDialog.setContentView(AppCompatDialog.java:83)
                                                         at android.support.v7.app.AlertController.installContent(AlertController.java:225)

AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="xxxxxxxxxx.chronicbrowser"
    android:versionCode="${versionCode}"
    android:versionName="${versionName}"
    android:installLocation="auto">

    <uses-sdk android:minSdkVersion="15" android:targetSdkVersion="22"/>
    <uses-permission android:name="com.android.vending.CHECK_LICENSE" />

    <uses-permission android:name="android.permission.INTERNET"></uses-permission>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>


    <supports-screens
        android:normalScreens="true"
        android:largeScreens="true"
        android:xlargeScreens="true"
        />

    <application android:name=".ChronicaApplication" android:largeHeap="true" android:icon="${iconpath}" android:label="@string/app_name" android:theme="@style/AppTheme">>
        <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/>
        <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="${facebookid}" />
            />

        <activity android:name=".ChronicBrowser"  android:configChanges="orientation|keyboardHidden|screenSize" android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

styles.xml:

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

My Activity is extending Activity

public class ChronicBrowser extends Activity {

Make the activity extend AppCompatActivity instead.

Most of the AppCompat stuff requires AppCompat classes, for an instance AppCompatActiviity or the fragment import from the support package i stead

尝试在清单的活动标签中添加android:theme =“ @ style / AppTheme”。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM