Showing posts with label jni. Show all posts
Showing posts with label jni. Show all posts

Wednesday, April 25, 2012

To access multiple dimensional array in Java from C using JNI

It is a little bit tricky to use jni to access matrix in java from c/c++ code. Here is my example:


I really hate the blogger. I can past my source code. Anyway, you can send me email about how to do it.

Here the "tags" is a two dimensional array in java. I would like to access its data and save them to a matrix "tagPos" in c/c++;

jni getobjectclass function error "SIGSEGV"

Here is my code :

    midMain = env->GetStaticMethodID( clsMTT, "TagCalculation", "()LReturnTags;");
        tagInfo = env->CallStaticObjectMethod(clsMTT, midMain, NULL);
        clsR = env->GetObjectClass(tagInfo);





When I run this program, I get the following the "SIGSEGV" error caused by GetObjectClass function.

The reason is the function "TagCalculation" returned a empty object "tagInfo" when I run "CallStaticObjectMethod".
Therefore, the GetObjectClass tries to find a class from an empty object. This will be wrong.
The solution is very simple: I change the function "TagCalculation" to always return a real object, which is not empty.
Then, the error gone.