user5158149
user5158149

Reputation:

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

I am getting the following error:

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)'

With this code:

// 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

I'm curious as to why the compiler thinks that this code is wrong.

Upvotes: 1

Views: 1280

Answers (2)

UserID0908
UserID0908

Reputation: 108

Just for those who are still getting the same error!

In my case i removed the reference to namespace

Android.Runtime

might be in your case

Android.Runtime.Extension

might help someone!

Upvotes: 3

gregoryp
gregoryp

Reputation: 1019

This happens when you have two methods with the same name but in different classes and Visual Studio needs to know which one you want to use.

Mouse over the error on the code and click on the 'light' icon and choose the method you want to use. You can also left click on the error onde the code and then press (ctrl + . (dot)) and choose the method you want.

enter image description here

enter image description here

Upvotes: 0

Related Questions