1

My question is simple, how can I instantiate Java objects on C++ (though JNI) and return an array of those created objects?

Something like:

jclass cls = g_jniEnv->FindClass("Lbr/com/iba/model/Annotation;");      
jmethodID meth = g_jniEnv->GetMethodID(cls, "setBookmark1", "(Ljava/lang/String;)V");

How I instantiate this cls object and call methods then return it from this method?

1 Answer 1

4

Actually, I solved it:

JNIEXPORT jobject JNICALL Java_com_rmsdk_wrapper_RMServices_getBookmarkNew(
    JNIEnv *env, jobject thiso) {
   jclass cls = g_jniEnv->FindClass("br/com/iba/model/Annotation");

   jobject obj = g_jniEnv->AllocObject(cls);

   jmethodID meth1 = g_jniEnv->GetMethodID(cls, "setBookmark1", "(Ljava/lang/String;)V");
   jmethodID meth2 = g_jniEnv->GetMethodID(cls, "setPage", "(I)V");

   jstring jAssetName = g_jniEnv->NewStringUTF("Bookmark qualquer");

   g_jniEnv->CallObjectMethod(obj, meth1, jAssetName);
   g_jniEnv->CallObjectMethod(obj, meth2, 2);

   return obj;
};
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.