2011-07-04 66 views
1

我的問題很簡單,我如何在C++上實例化Java對象(通過JNI)並返回這些創建對象的數組?JNI上的Java對象

喜歡的東西:

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

這怎麼我實例CLS對象,調用方法,然後從這個方法返回呢?

回答

4

其實,我解決了這個問題:

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; 
};