-1
對於將數據設置爲JNI並將數據導入到Java中有一些困難。我該怎麼辦?這裏請參考這段代碼,因爲我不知道我有什麼問題。請幫我解決這個問題。
Student.java
如何將數據設置爲JNI並檢索到java
public class Student {
private int age;
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
MainActivity.java
public class MainActivity extends AppCompatActivity {
static {
System.loadLibrary("native-lib");
}
public static native Student getStudentAge();
protected Student student;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
student = getStudentAge();
Log.d("TAG_DATA", String.valueOf(student.getAge()));
}
}
母語lib.cpp
JNIEXPORT jobject JNICALL
Java_com_example_helloJni_MainActivity_getStudentAge(JNIEnv *env, jclass type) {
jclass fStdClass = env->FindClass("com/example/helloJni/Student");
jobject nStdClass = env->AllocObject(fStdClass);
jmethodID methodId = env->GetMethodID(fStdClass, "setAge", "(I)V");
env->CallObjectMethod(nStdClass, methodId, 10);
return nStdClass;
}
錯誤:
JNI DETECTED ERROR IN APPLICATION: the return type of CallObjectMethodV does not match
請將您難以理解的問題翻譯成英文。 – EJP
@EJP抱歉我的英語不好。 –