JNI:NoSuchFieldError

时间:2009-12-08 00:32:02

标签: java android java-native-interface

输出:javap -s SomeClass

public org.someapp.SomeClass$_data data;
  Signature: Lorg/someapp/SomeClass$_data;

Java中SomeClass的定义:

class SomeClass
{
    private class _data {
        byte[] something = new byte[1234];
    }

    public _data data;
}

Java中本机函数的定义:

public static native int NativeFunction(SomeClass something);

Java实现:

SomeClass x = new SomeClass();
NativeInterface.NativeFunction(x);

但是,执行以下代码时:

JNIEXPORT jint JNICALL Java_org_someapp_NativeInterface_NativeFunction(JNIEnv* env, jobject obj, jobject someobject) {
    jclass some_class = (*env)->GetObjectClass(env, someobject);
    jfieldID data = (*env)->GetFieldID(env, some_class, "data", "Lorg/someapp/SomeClass$_data"); 
}

Java在GetFieldID调用上抛出“NoSuchFieldError;:data”异常。我不明白..签名很好(直接从javap复制)。

请注意,获取更简单变量的字段ID,如无符号短(带有签名“S”)的工作正常。

1 个答案:

答案 0 :(得分:6)

我觉得"Lorg/someapp/SomeClass$_data"应该是"Lorg/someapp/SomeClass$_data;"。注意分号。