类别:
package com.example.foo;
public class Dummy
{
int value;
public Dummy(int value)
{
this.value = value;
}
}
JNI片段:
jclass class = (*jni_env)->FindClass(jni_env, "com/example/foo/Dummy");
jmethodID constructor = (*jni_env)->GetMethodID(jni_env, class, "<init>", "(I)V");
jobject object = (*jni_env)->NewObject(jni_env, constructor, 0);
LogCat输出:
09-03 11:02:02.937: W/dalvikvm(2179): Invalid indirect reference 0x44e9cf80 in decodeIndirectRef
09-03 11:02:02.937: E/dalvikvm(2179): VM aborting
09-03 11:02:02.937: A/libc(2179): Fatal signal 11 (SIGSEGV) at 0xdeadd00d (code=1), thread 2179
答案 0 :(得分:2)
NewObject()
期望类对象指针作为第二个参数。构造方法ID是第三个参数。像这样重新制定:
jobject object = (*jni_env)->NewObject(jni_env, class, constructor, 17);
其中17是构造函数的参数。