Reputation: 157
i want to call method inside java and retrun a string to ndk but my app will crash when i calling java method . i checked more stackoverflow site but when im using other codes,it dont work. help me thanks
inside ndk code :
extern "C"
JNIEXPORT jstring JNICALL
Java_com_hppni_battleword_view_SplashScreen_tkk(JNIEnv *env, jclass type) {
jclass jClass = env->FindClass("com/hppni/battleword/view/SplashScreen");
if (jClass != nullptr) {
jmethodID mid2 = env->GetStaticMethodID(jClass, "encryptThisString",
"(Ljava/lang/String;)Ljava/lang/String;"); // app will crash here
if (mid2 != nullptr) {
env->CallStaticVoidMethod(jClass, mid2, (jstring) "ali"); // app will crash here
}
}
return env->NewStringUTF(getSignature(env));
}
inside java class/Activity :
public static String encryptThisString(String input) {
Log.d("NDK", input);
return input;
}
Upvotes: 0
Views: 175
Reputation: 2849
You can't just cast char *
string to jstring
. You need to create jstring
object using JNI functions like NewStringUTF
, for example.
Upvotes: 1