Skip to content

Instantly share code, notes, and snippets.

@mageddo
Last active November 8, 2022 17:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mageddo/6e8b394da8657d2026ad922359b3e42e to your computer and use it in GitHub Desktop.
Save mageddo/6e8b394da8657d2026ad922359b3e42e to your computer and use it in GitHub Desktop.
JNI call static method with arguments and return object
JNIEnv *jni;
// class and method finding
jclass clazz = jni->FindClass("java/lang/String");
jmethodID method = jni->GetStaticMethodID(clazz, "valueOf", "(Ljava/lang/Object;)Ljava/lang/String;");
if(method == NULL){
jni->FatalError("Class method not found\n");
}
// method execution
jstring arg1 = jni->NewStringUTF("Hello World!!!");
jstring result = (jstring) jni->CallStaticObjectMethod(clazz, method, arg1);
jni->ReleaseStringUTFChars(arg1, NULL);
if (result == NULL) {
jni->FatalError("couldn't call method");
}
// result presentation
jboolean isCopy = (jboolean) false;
printf("result: %s\n", jni->GetStringUTFChars(result, &isCopy));
@taru168175
Copy link

g

@taru168175
Copy link

#gg

@taru168175
Copy link

@taru168175
Ggg ggggg tggg

Ggg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment