0

I am working on a Unity3D & Android cross-platform project.

I want improve the performance, so I changed my code.

This is my first attempt.

In C#

string str = JO.Call<string> ("GetDevices");

in Java

public String GetDevices() {
      String devices = "";
      /* ... */
      return devices;
}

It works, but I don't like this.

So, I changed it like this:

In C#

string[,] str = new string[deviceNum,2];
str = JO.Call<string[,]> ("GetDevices");

In Java

public String[][] GetDevices() {
    String[][] devices = {{""}};
    /* ... */
    return devices;
}

But it doesn't work. What am I doing wrong?


This is my first attempt log :

 I/Unity: Exception: JNI: System.Array in n dimensions is not allowed
                                        at UnityEngine._AndroidJNIHelper.GetSignature (System.Object obj) [0x00000] in <filename unknown>:0 
                                        at UnityEngine._AndroidJNIHelper.GetSignature[String[,]] (System.Object[] args) [0x00000] in <filename unknown>:0 
                                        at UnityEngine._AndroidJNIHelper.GetMethodID[String[,]] (IntPtr jclass, System.String methodName, System.Object[] args, Boolean isStatic) [0x00000] in <filename unknown>:0 
                                        at UnityEngine.AndroidJNIHelper.GetMethodID[String[,]] (IntPtr jclass, System.String methodName, System.Object[] args, Boolean isStatic) [0x00000] in <filename unknown>:0 
                                        at UnityEngine.AndroidJavaObject._Call[String[,]] (System.String methodName, System.Object[] args) [0x00000] in <filename unknown>:0 
                                        at UnityEngine.AndroidJavaObject.Call[String[,]] (System.String methodName, System.Object[] args) [0x00000] in <filename unknown>:0 

And I tried "Pef" way and log like this

 07-18 10:21:58.318 18999-19055/? I/Unity: Exception: JNI: Unknown generic array type 'System.String[]'
                                        at UnityEngine._AndroidJNIHelper.ConvertFromJNIArray[String[][]] (IntPtr array) [0x00000] in <filename unknown>:0 
                                        at UnityEngine.AndroidJNIHelper.ConvertFromJNIArray[String[][]] (IntPtr array) [0x00000] in <filename unknown>:0 
                                        at UnityEngine.AndroidJavaObject._Call[String[][]] (System.String methodName, System.Object[] args) [0x00000] in <filename unknown>:0 
                                        at UnityEngine.AndroidJavaObject.Call[String[][]] (System.String methodName, System.Object[] args) [0x00000] in <filename unknown>:0 
1
  • @stefanobaghino Thank you stefanobaghino Commented Jul 18, 2017 at 0:43

2 Answers 2

1

You are using a multidimensional array in your C# code which is different from an array of arrays as you are using in your java code.

For more details on the difference look here: What are the differences between a multidimensional array and an array of arrays in C#?

You could try:

string[][] str = new string[2][];
str[0] = new string[deviceNum];
str[1] = new string[deviceNum];
str = JO.Call<string[][]> ("GetDevices");

And pay attention to the order of the array dimensions.

Sign up to request clarification or add additional context in comments.

2 Comments

If you only get back data you can omit the 2nd and 3rd line.
Thank you Pef, i tried your advice. But isn't solved.
0

Finally, I solve this problem

in c#

 string[] devicesstr = new string[deviceNum*2];
 devicesstr = tcamJO.Call<string[]> ("GetDevices");

in java

 public String[] GetDevices() {
 String[] devices = {"",};
 /* ... */
     devices = new String[cameraIds.length * 2];
     int j =0;
     for (int i = 0; i < cameraIds.length + 1; i += 2) {
           devices[i] = cameraIds[j++];
           /* .... */
           if (facing != null && facing == CameraCharacteristics.LENS_FACING_FRONT) {
               devices[i+1] = "1";
           } else {
               devices[i+1] = "0";
           }
      }
 }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.