JNI:NoSuchFieldError [英] JNI: NoSuchFieldError
问题描述
输出:javap的-s SomeClass的
Output of: javap -s SomeClass
public org.someapp.SomeClass$_data data;
Signature: Lorg/someapp/SomeClass$_data;
SomeClass的Java中定义:
Definition of SomeClass in Java:
class SomeClass
{
private class _data {
byte[] something = new byte[1234];
}
public _data data;
}
本机功能的Java的定义:
Definition of native function in Java:
public static native int NativeFunction(SomeClass something);
Java实现的:
Java implementation:
SomeClass x = new SomeClass();
NativeInterface.NativeFunction(x);
然而,当下列code为执行:
However, when the following code is executed:
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 ;:数据异常。我不明白这一点。该签名是蛮好的(从javap的直接复制)。
Java throws a "NoSuchFieldError;: data" exception on the GetFieldID call. I don't get it.. The signature is just fine (copied straight from javap).
注意在获取ID字段为一个简单的变量,像一个无符号短(带标志性的S)的作品就好了。
Note that getting the field ID for a simpler variable, like an unsigned short (with signature "S") works just fine.
推荐答案
我有一种感觉,Lorg / someapp / SomeClass的$ _data
应Lorg / someapp / SomeClass的$ _data;
。注意分号。
I have a feeling that "Lorg/someapp/SomeClass$_data"
should be "Lorg/someapp/SomeClass$_data;"
. Note the semicolon.
这篇关于JNI:NoSuchFieldError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!