I have declared a static native method in this way:
public native static void test(int w, int h);
And then I declared it in JNI in the way:
void testJni(JNIEnv* env, jint w, jint h)
Strangely, the w always received a value looks like a pointer, seems the jclass/jobject is passed to the first argument w.
Instead if the first argument is not a jint, say a jstring, things would be working fine.
Can somebody explain why this is happening? Thanks.
Your native declaration is incorrect. The second argument for static method is jclass, that corresponds to java class where method is placed.
Java:
public native static void test(int w, int h);
Native:
void testJni(JNIEnv* env, jclass clazz, jint w, jint h)
For native instance methods second arg is jobject, that corresponds to java's this
Java:
public native void test(int w, int h);
Native:
void testJni(JNIEnv* env, jobject thiz, jint w, jint h)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With