Java.Lang.NoSuchMethodError:没有非静态方法“ Landroid / content / Context; .getColorStateList(I)Landroid / content / res / ColorStateList;”

时间:2019-01-11 07:26:39

标签: android xamarin xamarin.android

查看我的日志

Java.Lang.NoSuchMethodError: no non-static method "Landroid/content/Context;.getColorStateList(I)Landroid/content/res/ColorStateList;"
01-11 12:48:49.249 I/MonoDroid( 9688):   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <fcbf47a04b2e4d90beafbae627e1fca4>:0 
01-11 12:48:49.249 I/MonoDroid( 9688):   at Java.Interop.JniEnvironment+InstanceMethods.GetMethodID (Java.Interop.JniObjectReference type, System.String name, System.String signature) [0x0005b] in <3cb12bce834a498199b2be6cd3e00922>:0 
01-11 12:48:49.249 I/MonoDroid( 9688):   at Java.Interop.JniType.GetInstanceMethod (System.String name, System.String signature) [0x0000c] in <3cb12bce834a498199b2be6cd3e00922>:0 
01-11 12:48:49.249 I/MonoDroid( 9688):   at Java.Interop.JniPeerMembers+JniInstanceMethods.GetMethodInfo (System.String encodedMember) [0x00031] in <3cb12bce834a498199b2be6cd3e00922>:0 
01-11 12:48:49.249 I/MonoDroid( 9688):   at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeNonvirtualObjectMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x00006] in <3cb12bce834a498199b2be6cd3e00922>:0 
01-11 12:48:49.249 I/MonoDroid( 9688):   at Android.Content.Context.GetColorStateList (System.Int32 id) [0x00022] in <551e90b840814b76a3d15b7bbaa8a77c>:0 
01-11 12:48:49.249 I/MonoDroid( 9688):   at Movo.MapActivity+<OnCreate>d__37.MoveNext () [0x000a6] in C:\Users\MapActivity.cs:85 An unhandled exception occured.

1 个答案:

答案 0 :(得分:2)

在API级别23中添加了基于上下文GetColorStateList,因此,如果您尝试在较旧的Android版本上执行该方法,则会失败。

现在,在com.android.support:support-compat(24.1及更高版本)中(通过Xamarin Nuget Xamarin.Android.Support.Compat),有一个基于 ContextCompat GetColorStateList用于较旧(和较新)的API级别