How to return an interger array from JNI to java layer?
Vinney Shanmugam
Ranch Hand
Joined: Aug 27, 2008
Posts: 104
posted
0
i have a native code, where i ll be filling up an array of integers. I want to return this to java layer.
Can i create a arraylist in java to get these back in java layer?
Campbell Ritchie wrote:Thank you, Rob. Does that apply only in Java? I suppose there is no such thing as an Object[] in C/C++.
To be honest, I have no idea. I've done quite some C programming, but my C++ experience is lacking.
Did you miss out a "not" somewhere, maybe "not mix"?
I didn't, but my intentions seem to be missing.
What I was trying to say is, that Vinod should use NewObjectArray to create one Object array as the outer array (of type int[].class which is [I in native code), then use NewIntArray to create each int[] element, and finally use SetObjectArrayElement to set these as the values of the Object array.
In pseudo code:
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32689
4
posted
0
Right, thank you, Rob. All explained. I am pretty sure there is not usually an Object in C, so there can't be an Object[], unless you create such a type yourself. Presumably as a struct.