Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Complex Array initialization in JNI

Here is my java-code which i want to convert into JNI.
How can I do this type of stuff?

Code :

public class ArrayTest
{
  public static void main(String[] args)
  {
    int[][] a = new int[11][3];
    int[] b;

    for(int i = -5 ; i <=5; i++){
      b = a[i + 5];
      System.out.println(b.length);
    }
  }
}
like image 482
Kishan Donga Avatar asked Feb 06 '26 04:02

Kishan Donga


1 Answers

I don't understand, which logic contains in your code, but I just show you example how to create multidirectional array:

jclass intArrayClass = env->FindClass("[I");
// create outher array
jobjectArray a = env->NewObjectArray(11, intArrayClass, NULL);
// initialize inner array
for(int i = 0; i < 11; i++)
    env->SetObjectArrayElement(imgArray, i, env->NewIntArray(3));

jintArray b;
for(int i = -5 ; i <=5; i++){
    b = (jintArray)env->GetObjectArrayElement(a, i + 5);
    // print lenght of b array
}
like image 161
Sergey Bubenshchikov Avatar answered Feb 07 '26 22:02

Sergey Bubenshchikov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!