2011-12-15 56 views
1

Java類有getLong()getCharArray()方法,我有jobject鏈接到這個類。JNI:調用帶有「()[C」簽名的Java方法

此代碼

jclass clsData = env->GetObjectClass(data); 
jmethodID getVal = env->GetMethodID(clsData, "getLong", "()J"); 
jlong x = env->CallLongMethod(data, getVal); 

給我訪問由getLong()返回長值。

jclass clsData = env->GetObjectClass(data); 
jmethodID getVal = env->GetMethodID(clsData, "getCharArray", "()[C"); 
??? 

如何訪問字符數組?

回答

4

就可以得到字符數組這樣的方式,這是從另一篇文章簡單的代碼片段完整後here

jobject obj = ... // This is the object you want to call the method on 
jcharArray arr = (jcharArray) (*env)->CallObjectMethod(env, obj, getVal); 
int count = (*env)->GetArrayLength(env, arr); 
jchar* chars = (*env)->GetCharArrayElements(env, arr, 0);