0

班级:

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
4

1 回答 1

2

NewObject()期望类对象指针作为第二个参数。构造方法ID是第三个参数。像这样重新制定:

jobject object = (*jni_env)->NewObject(jni_env, class, constructor, 17); 

其中 17 是构造函数的参数。

于 2012-09-03T18:59:39.557 回答