Android ndk : Problem for call of Java method from c++ with jni

前端 未结 2 1237
栀梦
栀梦 2021-02-05 05:47

I try to work on Android NDK, my first test are not very conclusive, I need for help because I don\'t see where is my error.

The following code compiles without problem

相关标签:
2条回答
  • 2021-02-05 06:25

    What you have looks okay to me... but you might try replacing

    jclass clazz = env->FindClass("com/test/jnitest/JNITestActivity");
    

    With

    jclass clazz = env->GetObjectClass(obj);
    
    0 讨论(0)
  • 2021-02-05 06:31

    After one day lost due to this bug, i finally found the solution of my problem :

    The function javaCallJNI() is declared as a static native in Java, but, a static method can't call a non static method...

    For resolve this problem, just replace :

    public static native void javaCallJNI();
    

    by

    public native void javaCallJNI();
    

    in JNITestActivity.java

    Thank for your help and see soon ;)

    0 讨论(0)
提交回复
热议问题