我试图调用我使用Android NDK从C编写的一些Java代码.该应用程序是NativeActivity应用程序.我必须访问一些仅在Java中可用的功能,并且该功能要求您子类化另一个类,所以我不能直接从C执行调用.因此,我有这样的Java代码:
// src/com/example/my/package/SubClass.java
package com.example.my.package;
import android.foo.TheSuperClass;
public class SubClass extends TheSuperClass {
public SubClass() {
setImportantProperty(true);
}
}
Run Code Online (Sandbox Code Playgroud)
我也有这样的C代码:
// Some file.c
void setThatImportantJavaProperty() {
JavaVM *vm = AndroidGetJavaVM(); // This returns a valid JavaVM object
JNIEnv* env;
(*vm)->AttachCurrentThread(vm, &env, 0);
jclass theSubClass = (*env)->FindClass(env, "com/example/my/package/SubClass");
jthrowable exception = (*env)->ExceptionOccurred(env);
if (exception) {
(*env)->ExceptionDescribe(env);
// This gives me: "java.lang.NoClassDefFoundError: [generic]".
// Also, theSubClass is null, so the next line causes a segfault.
}
jmethodID theSubClassConstructor = (*env)->GetMethodID(env, theSubClass, …Run Code Online (Sandbox Code Playgroud)