查看我的日志
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.
最佳答案
在API级别23中添加了基于上下文的GetColorStateList
,因此,如果尝试在较旧的Android版本上执行该方法,它将失败。
现在,在com.android.support:support-compat
(版本24.1及更高版本)中(通过Xamarin Nuget Xamarin.Android.Support.Compat),有一个基于ContextCompat的GetColorStateList
可用于较旧(和较新)的API级别