mlipman
mlipman

Reputation: 356

Calling Java Method from Android NDK SIGSEGV

I am trying to call a java method from NDK code. the C++ code is:

extern "C" JNIEXPORT jboolean JNICALL
Java_com_lipman_whiteboard_CameraProcessing_processBitmap(JNIEnv * env, jobject obj)
{
jclass callingClass = env->GetObjectClass(obj);
jmethodID mid = env->GetMethodID(callingClass, "setProgressMax", "(I)V");
env->CallVoidMethod(obj, mid, 7);
}

"mid" is always null in the above snippet. The relevant parts of the java class are:

public class CameraProcessing
{
private static native boolean processBitmap();

private void setProgressMax(int max)
{
}

Does anyone know why "mid" is always null? What am I doing wrong?

Upvotes: 3

Views: 748

Answers (1)

fadden
fadden

Reputation: 52343

You've declared the native processBitmap() method to be static, which means the second argument is a jclass rather than a jobject. When you call GetObjectClass, you're actually getting the class of the jclass, which means callingClass is simply java.lang.Class, which does not define a setProgressMax method. There should be an exception pending with a message to that effect.

Change the declaration to:

private native boolean processBitmap();

and try again.

Calling a private method should not be a problem from JNI.

Also, make sure you check for exceptions after CallVoidMethod returns.

Upvotes: 3

Related Questions