java.lang.NoSuchFieldError: no "I" field XXXXin class "Lxx/xx/xx/xx;" or its superclasses
2016-11-10 16:41
555 查看
用C语言写jni调用的时候,先FindClass ,之后通过GetFieldID 获取变量 然后通过SetIntField 等 去赋值
大约的流程如下:
// 获取类
clsDay = (*env)->FindClass(env, "com/xxx/xxx/xxxx/Day");
//获取method ,一般都是固定写法
jmethodID mid_init = (*env)->GetMethodID(env, clsDay , "<init>", "()V");
//创建对象
jobject data_struct = (*env)->NewObject(env, clsDay , mid_init);
//获取类里的变量
jfieldID type = (*env)->GetFieldID(env, clsDay , "type", "I");
jfieldID mon= (*env)->GetFieldID(env, clsDay , "mon", "F");
//给变量赋值
(*env)->SetIntField(env, data_struct, type, 1);
(*env)->SetFloatField(env, data_struct, mon, 12.00f);
如果类Day里面有
{
int type;
float mon;
}
但老是找不到type
java.lang.NoSuchFieldError: no "I" field type in class "Lxx/xx/xx/xx;" or its superclasses
大约的流程如下:
// 获取类
clsDay = (*env)->FindClass(env, "com/xxx/xxx/xxxx/Day");
//获取method ,一般都是固定写法
jmethodID mid_init = (*env)->GetMethodID(env, clsDay , "<init>", "()V");
//创建对象
jobject data_struct = (*env)->NewObject(env, clsDay , mid_init);
//获取类里的变量
jfieldID type = (*env)->GetFieldID(env, clsDay , "type", "I");
jfieldID mon= (*env)->GetFieldID(env, clsDay , "mon", "F");
//给变量赋值
(*env)->SetIntField(env, data_struct, type, 1);
(*env)->SetFloatField(env, data_struct, mon, 12.00f);
如果类Day里面有
{
int type;
float mon;
}
但老是找不到type
java.lang.NoSuchFieldError: no "I" field type in class "Lxx/xx/xx/xx;" or its superclasses
关于这个报错,排查了很多次, 发现,如果你在Day这个类里面,没有去使用type, 就会报这个错误。所以在写代码时,一些编辑器给的警告也要注意下。
相关文章推荐
- java.lang.NoSuchFieldError: No static field xxx of type I in class Lcom/XX/R$id; or its superclasses
- java.lang.NoSuchFieldError: No static field xxx of type I in class Lcom/XX/R$id; or its superclasses
- Android java.lang.NoSuchFieldError: No static field xxx of type I in class Lcom/XX/R$id; or its superclasses
- java.lang.NoSuchFieldError: No static field xxx of type I in class Lcom/XX/R$id; or its superclasses
- 二、Java.lang.NoSuchFieldError: No static field xxx of type I in class Lcom/XX/R$id; or
- java.lang.NoSuchFieldError: No static field ib_back of type I in class Lcom/example/demo/R$id; or
- java.lang.NoSuchFieldError: No static field txt_content of type I in class Lcom/test/
- elasticsearch 报出 Exception in thread "main" java.lang.NoSuchFieldError: LUCENE_3_6
- Exception in thread "main" java.lang.NoSuchFieldError的 一种解决办法
- hive Exception in thread "main" java.lang.NoSuchFieldError: type
- Exception in thread "main" java.lang.NoSuchFieldError: level
- Exception in thread "main" java.lang.NoSuchFieldError: INSTANCE
- NoSuchFieldError: No static field btn_press3 of type I in class Lcom/hyphenate/helpdesk/R$id; or its
- Exception in thread "main" java.lang.RuntimeException: java.lang.NoSuchFieldException: versionID
- java 错误"main" java.lang.NoSuchFieldError: INSTANCE
- GeoServer启动错误Error on startup, "java.lang.NoSuchFieldError KEY_CACHED_TILE_RECYCLING_ENABLED"
- mybatis "There is no getter for property named 'xx' in 'class java.lang.String"问题
- java.lang.NoSuchFieldError: INSTANCE in HttpClient when running hadoop
- Fatal Error: Unable to find package java.lang in classpath or bootclasspath
- java.lang.NoSuchFieldError: deferredExpression异常