c# - Xamarin.Android : The call is ambiguous between the following methods or properties

标签 c# compiler-errors xamarin.android jnienv

我收到以下错误:

The call is ambiguous between the following methods or properties: 'Java.Interop.JavaObjectExtensions.JavaCast(Android.Runtime.IJavaObject)' and 'Android.Runtime.Extensions.JavaCast(Android.Runtime.IJavaObject)'



使用此代码:
// Get a pointer to the Java class.
IntPtr jClass = JNIEnv.FindClass("com/companyname/appname/JniClass");

// constructor.
IntPtr defaultConstructor = JNIEnv.GetMethodID(jClass,
                                               "<init>",
                                               "()V");
// new instance of the class.
IntPtr instance = JNIEnv.NewObject(jClass, defaultConstructor);

// Find method.
IntPtr methodID = JNIEnv.GetMethodID(jClass,   "getResult",    "()Ljava/lang/String;");

// Call the method.
IntPtr resultPtr = JNIEnv.CallObjectMethod(instance, methodID);

// Convert the pointer to return value
Java.Lang.Object jObject = new Java.Lang.Object(resultPtr, JniHandleOwnership.TransferLocalRef);
Java.Lang.String result = jObject.JavaCast<Java.Lang.String>(); // Compiler Error

我很好奇为什么编译器认为此代码是错误的。

最佳答案

仅针对那些仍然遇到相同错误的人!

就我而言,我删除了对命名空间的引用

Android.Runtime

可能在您的情况下
Android.Runtime.Extension

可能会帮助某人!

关于c# - Xamarin.Android : The call is ambiguous between the following methods or properties,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42776321/

相关文章:

javascript - 从 POST 收到的响应已损坏

c++ - 类型 'double' 和 'int' 到二进制 'operator%' 的无效操作数

c# - 使用 PowerShell 在 c# 结构中设置值

c# - Serilog 和 .NET Core 2.1 HostBuilder 配置

python - cython编译错误: multiple definition of functions

c# - 覆盖 FloatingActionButton.Behavior 中的方法时 Xamarin Android 名称发生冲突

android - 工具栏后退/主页按钮的 Xamarin 资源 ID 与 Resource.Id.home 不匹配

android - 图标左侧的菜单资源项位置标题

c# - LINQ - 单运算符(operator)

c++ - SFINAE 尝试使用 bool 给出编译器错误 : "template argument ‘T::value’ involves template parameter"