我在Java中有这个类:
public class CameraActivity extends Activity {
...
public class RecognitionResult {
public String text;
public int x;
public int y;
public int width;
public int height;
public RecognitionResult(String text, int x, int y, int width, int height) {
this.text = text;
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
}
}
这是我的 JNI 代码:
extern "C"
jobject Java_com_example_parkingcontrolsystem_CameraActivity_recognizeNumberPlate(JNIEnv *env,
jobject object,
jstring filename)
{
jclass cls = env->FindClass("com/example/parkingcontrolsystem/CameraActivity$RecognitionResult");
std::cout << "Class: " << cls << std::endl;
jmethodID constructor = env->GetMethodID(cls, "<init>", "(Ljava/lang/String;IIII)V");
std::cout << "Method: " << constructor << std::endl;
recognition_result = env->NewObject(cls, constructor, "Hello from JNI", 0, 0, 50, 100);
std::cout << "Object: " << recognition_result << std::endl;
return recognition_result;
}
FindClass 返回不是 NULL,OK。但是 GetMethodID 总是返回零。我试图制作没有参数的默认构造函数,而不是使用“()V”签名,但GetMethodID返回NULL。
怎么了?