您需要使用此活动错误的Theme.AppCompat主题(或后代)

时间:2016-08-01 23:02:03

标签: android android-layout xamarin.android

我正在使用Xamarin来开发我的Android应用程序。运行应用程序时出现此错误。 AppCompat中的主要活动类范围。我知道我需要使用AppCompat主题,我认为我正在做。 在我的样式文件中,我有这个:

    <style name="MyTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">#2196F3</item>
    <item name="drawerArrowStyle">@style/MyDrawerArrowStyle</item>
</style>

<style name="MyDrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
    <item name="color">#F5F5F5</item>
    <item name="spinBars">true</item>
</style>

在我的AndroidManifest应用程序标签中,我有这个:

<application android:label="SuperMarket" android:theme="@style/MyTheme" android:name="mono.android.app.Application" android:allowBackup="true" android:icon="@drawable/icon" android:debuggable="true">
<activity android:icon="@drawable/icon" android:label="SuperMarket" android:theme="@style/MyTheme" android:name="md5aac27d1f54e5651bf56c7cf1fe703c82.MainActivity">

当我的自定义主题是AppCompat主题的后代时,我不明白为什么我会收到此错误。 我甚至尝试使用Theme.AppCompat.Light而不是我的自定义主题但仍然出现此错误。

修改

这是完整的堆栈跟踪

    08-02 04:06:41.567 E/mono    (24282): 
08-02 04:06:41.567 E/mono    (24282): Unhandled Exception:
08-02 04:06:41.567 E/mono    (24282): Java.Lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
08-02 04:06:41.567 E/mono    (24282):   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/3053/a94a03b5/source/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143 
08-02 04:06:41.567 E/mono    (24282):   at Android.Runtime.JNIEnv.CallNonvirtualVoidMethod (IntPtr jobject, IntPtr jclass, IntPtr jmethod, Android.Runtime.JValue* parms) [0x00084] in /Users/builder/data/lanes/3053/a94a03b5/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:1029 
08-02 04:06:41.567 E/mono    (24282):   at Android.App.Activity.SetContentView (Int32 layoutResID) [0x00070] in /Users/builder/data/lanes/3053/a94a03b5/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Android.App.Activity.cs:5872 
08-02 04:06:41.567 E/mono    (24282):   at SuperMarket.MainActivity.OnCreate (Android.OS.Bundle bundle) [0x00009] in c:\Users\Ahmed\Documents\Visual Studio 2013\Projects\SuperMarket\SuperMarket\Activities\MainActivity.cs:29 
08-02 04:06:41.567 E/mono    (24282):   at Android.Support.V4.App.FragmentActivity.n_OnCreate_Landroid_os_Bundle_ (IntPtr jnienv, IntPtr native__this, IntPtr native_savedInstanceState) [0x00011] in <filename unknown>:0 
08-02 04:06:41.567 E/mono    (24282):   at (wrapper dynamic-method) System.Object:cda09668-a60c-4d59-9b25-7606e0b35a8c (intptr,intptr,intptr)
08-02 04:06:41.567 E/mono    (24282):   --- End of managed exception stack trace ---
08-02 04:06:41.567 E/mono    (24282): java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
08-02 04:06:41.567 E/mono    (24282):   at android.support.v7.app.AppCompatDelegateImplV7.createSubDecor(AppCompatDelegateImplV7.java:343)
08-02 04:06:41.567 E/mono    (24282):   at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:312)
08-02 04:06:41.567 E/mono    (24282):   at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:277)
08-02 04:06:41.567 E/mono    (24282):   at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
08-02 04:06:41.567 E/mono    (24282):   at md5aac27d1f54e5651bf56c7cf1fe703c82.MainActivity.n_onCreate(Native Method)
08-02 04:06:41.567 E/mono    (24282):   at md5aac27d1f54e5651bf56c7cf1fe703c82.MainActivity.onCreate(MainActivity.java:28)
08-02 04:06:41.567 E/mono    (24282):   at android.app.Activity.performCreate(Activity.java:4465)
08-02 04:06:41.567 E/mono    (24282):   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
08-02 04:06:41.567 E/mono    (24282):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1931)
08-02 04:06:41.567 E/mono    (24282):   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
08-02 04:06:41.567 E/mono    (24282):   at android.app.ActivityThread.access$600(ActivityThread.java:127)
08-02 04:06:41.567 E/mono    (24282):   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
08-02 04:06:41.567 E/mono    (24282):   at android.os.Handler.dispatchMessage(Handler.java:99)
08-02 04:06:41.567 E/mono    (24282):   at android.os.Looper.loop(Looper.java:137)
08-02 04:06:41.567 E/mono    (24282):   at android.app.ActivityThread.main(ActivityThread.java:4441)
08-02 04:06:41.567 E/mono    (24282):   at java.lang.reflect.Method.invokeNative(Native Method)
08-02 04:06:41.567 E/mono    (24282):   at java.lang.reflect.Method.invoke(Method.java:511)
08-02 04:06:41.567 E/mono    (24282):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:823)
08-02 04:06:41.567 E/mono    (24282):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:590)
08-02 04:06:41.567 E/mono    (24282):   at dalvik.system.NativeStart.main(Native Method)
08-02 04:06:41.567 E/mono    (24282): 
08-02 04:06:41.567 E/mono-rt (24282): [ERROR] FATAL UNHANDLED EXCEPTION: Java.Lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
08-02 04:06:41.567 E/mono-rt (24282):   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/3053/a94a03b5/source/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143 
08-02 04:06:41.567 E/mono-rt (24282):   at Android.Runtime.JNIEnv.CallNonvirtualVoidMethod (IntPtr jobject, IntPtr jclass, IntPtr jmethod, Android.Runtime.JValue* parms) [0x00084] in /Users/builder/data/lanes/3053/a94a03b5/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:1029 
08-02 04:06:41.567 E/mono-rt (24282):   at Android.App.Activity.SetContentView (Int32 layoutResID) [0x00070] in /Users/builder/data/lanes/3053/a94a03b5/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Android.App.Activity.cs:5872 
08-02 04:06:41.567 E/mono-rt (24282):   at SuperMarket.MainActivity.OnCreate (Android.OS.Bundle bundle) [0x00009] in c:\Users\Ahmed\Documents\Visual Studio 2013\Projects\SuperMarket\SuperMarket\Activities\MainActivity.cs:29 
08-02 04:06:41.567 E/mono-rt (24282):   at Android.Support.V4.App.FragmentActivity.n_OnCreate_Landroid_os_Bundle_ (IntPtr jnienv, IntPtr native__this, IntPtr native_savedInstanceState) [0x00011] in <filename unknown>:0 
08-02 04:06:41.567 E/mono-rt (24282):   at (wrapper dynamic-method) System.Object:cda09668-a60c-4d59-9b25-7606e0b35a8c (intptr,intptr,intptr)
08-02 04:06:41.567 E/mono-rt (24282):   --- End of managed exception stack trace ---
08-02 04:06:41.567 E/mono-rt (24282): java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
08-02 04:06:41.567 E/mono-rt (24282):   at android.support.v7.app.AppCompatDelegateImplV7.createSubDecor(AppCompatDelegateImplV7.java:343)
08-02 04:06:41.567 E/mono-rt (24282):   at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:312)
08-02 04:06:41.567 E/mono-rt (24282):   at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:277)
08-02 04:06:41.567 E/mono-rt (24282):   at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
08-02 04:06:41.567 E/mono-rt (24282):   at md5aac27d1f54e5651bf56c7cf1fe703c82.MainActivity.n_onCreate(Native Method)
08-02 04:06:41.567 E/mono-rt (24282):   at md5aac27d1f54e5651bf56c7cf1fe703c82.MainActivity.onCreate(MainActivity.java:28)
08-02 04:06:41.567 E/mono-rt (24282):   at android.app.Activity.performCreate(Activity.java:4465)
08-02 04:06:41.567 E/mono-rt (24282):   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
08-02 04:06:41.567 E/mono-rt (24282):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1931)
08-02 04:06:41.567 E/mono-rt (24282):   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
08-02 04:06:41.567 E/mono-rt (24282):   at android.app.ActivityThread.access$600(ActivityThread.java:127)
08-02 04:06:41.567 E/mono-rt (24282):   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
08-02 04:06:41.567 E/mono-rt (24282):   at android.os.Handler.dispatchMessage(Handler.java:99)
08-02 04:06:41.567 E/mono-rt (24282):   at android.os.Looper.loop(Looper.java:137)
08-02 04:06:41.567 E/mono-rt (24282):   at android.app.ActivityThread.main(ActivityThread.java:4441)
08-02 04:06:41.567 E/mono-rt (24282):   at java.lang.reflect.Method.invokeNative(Native Method)
08-02 04:06:41.567 E/mono-rt (24282):   at java.lang.reflect.Method.invoke(Method.java:511)
08-02 04:06:41.567 E/mono-rt (24282):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:823)
08-02 04:06:41.567 E/mono-rt (24282):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:590)
08-02 04:06:41.567 E/mono-rt (24282):   at dalvik.system.NativeStart.main(Native Method)

0 个答案:

没有答案