Theme.AppCompat主题堆栈跟踪。在我的案例中找不到解决方案

时间:2017-12-05 10:33:16

标签: java android dialog android-styles

我尝试在我的Activity中显示一个对话框,我收到此错误: "您需要使用Theme.AppCompat主题"

关于此问题有很多问题/答案,但我不能在我的情况下得到它: 有人能帮我吗 ?我知道它与应用主题有关,但我认为这在我的情况下是可以的。可以请有人看看:

错误:

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>

我的活动正在扩展活动

public class ChronicBrowser extends Activity {

2 个答案:

答案 0 :(得分:1)

让活动扩展 var number = document.getElementById('ctc'); number.onkeydown = function(e) { if(!((e.keyCode > 95 && e.keyCode < 106) || (e.keyCode > 47 && e.keyCode < 58) || e.keyCode == 8)) { return false; } }

大多数AppCompat的东西都需要AppCompat类,对于一个实例AppCompatActiviity或从支持包中导入片段而不是

答案 1 :(得分:1)

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