0

I am trying to return an array from C program to Java, but it returns me the error "incompatible pointer to integer conversion returning 'int *' from a function with result type 'jint' (aka 'int'); dereference with * [-Wint-conversion]"

What I want to achieve is to use the array returned by this in a java program. Can someone please give an example on how I can do this.

JNIEXPORT jint JNICALL Java_com_ControlStub_alg1Value
(JNIEnv *env, jobject jobj) {
    return 3212;       
}

For example am using the above and using this function to just display its value in Java , similarly I need it to return an array. As am new to Java I am finding it difficult to do this , please help me. Thanks in advance!

Edit1: I already checked this link, but its confusing me as I said am still new to Java.

Jave Native Interface(JNI)

  • In addition to the linked question with answers, be sure that you do use the javah utility, which is a step in the tutorial that you referenced. – Tom Blodget Aug 13 '17 at 11:45
  • I want the JNI to retrun a simple array of Strings, but when i try to run the program as suggested in the already answered question I get the System.out.println(getStrings()); output to be something like this "[Ljava.lang.String;@1c59d3ae" and I dont understand what this implies –  Aug 16 '17 at 07:02
  • That's a Java question: It's simply the result of calling [Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--) on an array of strings. It shows that the object is an array of strings. – Tom Blodget Aug 16 '17 at 16:25

1 Answers1

0

Take a look here:

passing primitives array from Java to C and back (commit changes)

And here, if you want to pass something that is allocated inside C

passing memory allocated in C back to Java

Oo.oO
  • 12,464
  • 3
  • 23
  • 45