vanKraster-4073 avatar image
0 Votes"
vanKraster-4073 asked YonglunLiu-MSFT commented

Call method from aar file give error when cast Generic.Ilist<string> to Java.Ilist<string>

Hi to all,
As mentioned I have successfully imported and used some methods from aar file in my xamarin project, but ONE METHOD gives me error.

The method signature is this:

 // Metadata.xml XPath method reference: path="/api/package[@name='']/class[@name='ScioCloud']/method[@name='analyze' and count(parameter)=3 and parameter[1][@type=''] and parameter[2][@type='java.util.List&lt;java.lang.String&gt;'] and parameter[3][@type='']]"
 [Register ("analyze", "(Lcom/consumerphysics/android/sdk/model/ScioReading;Ljava/util/List;Lcom/consumerphysics/android/sdk/callback/cloud/ScioCloudAnalyzeManyCallback;)V", "GetAnalyze_Lcom_consumerphysics_android_sdk_model_ScioReading_Ljava_util_List_Lcom_consumerphysics_android_sdk_callback_cloud_ScioCloudAnalyzeManyCallback_Handler")]
 public virtual unsafe void Analyze (global::Com.Consumerphysics.Android.Sdk.Model.ScioReading p0, global::System.Collections.Generic.IList<string> p1, global::Com.Consumerphysics.Android.Sdk.Callback.Cloud.IScioCloudAnalyzeManyCallback p2)
 const string __id = "analyze.(Lcom/consumerphysics/android/sdk/model/ScioReading;Ljava/util/List;Lcom/consumerphysics/android/sdk/callback/cloud/ScioCloudAnalyzeManyCallback;)V";
 IntPtr native_p1 = global::Android.Runtime.JavaList<string>.ToLocalJniHandle (p1);
 try {
 JniArgumentValue* __args = stackalloc JniArgumentValue [3];
 __args [0] = new JniArgumentValue ((p0 == null) ? IntPtr.Zero : ((global::Java.Lang.Object) p0).Handle);
 __args [1] = new JniArgumentValue (native_p1);
 __args [2] = new JniArgumentValue ((p2 == null) ? IntPtr.Zero : ((global::Java.Lang.Object) p2).Handle);
 _members.InstanceMethods.InvokeVirtualVoidMethod (__id, this, __args);
 } finally {
 JNIEnv.DeleteLocalRef (native_p1);
 global::System.GC.KeepAlive (p0);
 global::System.GC.KeepAlive (p1);
 global::System.GC.KeepAlive (p2);

As You can see it translates the list to java list here: IntPtr native_p1 = global::Android.Runtime.JavaList<string>.ToLocalJniHandle (p1);
The method is 100% functionally in Java, only in xamarin it gives the error bellow.

When I call the method I have this error

“{Java.Lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String org.json.JSONObject.toString()' on a null object reference
at Java.Interop.JniEnvironment+InstanceMethods.CallVoidMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x0006e] in <1921523bc22e407fa9a0855bdae29335>:0
at Android.Runtime.JNIEnv.CallVoidMethod (System.IntPtr jobject, System.IntPtr jmethod, Android.Runtime.JValue* parms) [0x00000] in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNIEnv.g.cs:264
at Com.Consumerphysics.Android.Sdk.Sciosdk.ScioCloud.Analyze (Com.Consumerphysics.Android.Sdk.Model.ScioReading p0, System.Collections.Generic.IList`1[T] p1, Com.Consumerphysics.Android.Sdk.Callback.Cloud.IScioCloudAnalyzeManyCallback p2) [0x00085] in C:\Users\dmaruggi\Mobile\FTS21_library_simple app\ScioLibrary\SCiOLibrary\AARSCiO\obj\Debug\generated\src\Com.Consumerphysics.Android.Sdk.Sciosdk.ScioCloud.cs:257
at SCiOLibrary.Android.Cloud.ScioCloudAndroid.AnalyzeModels (System.Collections.Generic.IList`1[T] modelIdsToAnalyze) [0x00057] in C:\Users\dmaruggi\Mobile\FTS21_library_simple app\ScioLibrary\SCiOLibrary\SCiOLibrary\Android\Cloud\
--- End of managed Java.Lang.NullPointerException stack trace ---
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String org.json.JSONObject.toString()' on a null object reference
at crc64f81d35e176148202.ScioScanHandlerBool.n_onSuccess(Native Method)
at crc64f81d35e176148202.ScioScanHandlerBool.onSuccess(
at android.os.Handler.handleCallback(
at android.os.Handler.dispatchMessage(
at android.os.Looper.loop(
at java.lang.reflect.Method.invoke(Native Method)

· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Attempt to invoke virtual method 'java.lang.String org.json.JSONObject.toString()' on a null object reference.

The exception indicates that you are trying to dereference something that is null.

Have you checked the error line that the stack trace mentioned?

I suggest that when you are about to create the JSON object to pass into prepareAnalyzeJson, you should print out the string or log it to a file, so you can see what is missing.

0 Votes 0 ·

Hi, I cannot edit the aar file cause is not mine. But I assure you I send all parameters not null... I am quite sure that is an error while converting from C# list to Java List

0 Votes 0 ·

As far as the information is currently available, we cannot reproduce this issue.

If you could make sure that the issue is caused by converting from C# list to Java List, you could refer to Report a problem with the Visual Studio product or installer to report the problem to our tech team.

0 Votes 0 ·

0 Answers