Jni使用过程中出现 error: request for member 'FindClass' in something not a structure or union,解决办法-阿里云开发者社区

开发者社区> 开发与运维> 正文
登录阅读全文

Jni使用过程中出现 error: request for member 'FindClass' in something not a structure or union,解决办法

简介:
原文:http://topic.csdn.net/u/20110120/10/ef601a64-27fa-4a80-96be-39dbcb644cbc.html

问题:

在android 里使用JNI,总是报错
packages/apps/SystemMointor/jni/proc_reader.c:78: error: request for member 'GetStringUTFChars' in something not a structure or union
packages/apps/SystemMointor/jni/proc_reader.c:92: error: request for member 'FindClass' in something not a structure or union
packages/apps/SystemMointor/jni/proc_reader.c:94: error: request for member 'NewObjectArray' in something not a structure or union
packages/apps/SystemMointor/jni/proc_reader.c:96: error: request for member 'FindClass' in something not a structure or union
packages/apps/SystemMointor/jni/proc_reader.c:98: error: request for member 'GetFieldID' in something not a structure or union
packages/apps/SystemMointor/jni/proc_reader.c:99: error: request for member 'GetFieldID' in something not a structure or union
packages/apps/SystemMointor/jni/proc_reader.c:108: error: request for member 'SetObjectField' in something not a structure or union
packages/apps/SystemMointor/jni/proc_reader.c:108: error: request for member 'NewStringUTF' in something not a structure or union
packages/apps/SystemMointor/jni/proc_reader.c:116: error: request for member 'SetObjectField' in something not a structure or union
packages/apps/SystemMointor/jni/proc_reader.c:118: error: request for member 'SetObjectArray' in something not a structure or union


解决办法:

问题解决了,原来是这样的:
如果是c程序,要用 (*env)->
如果是C++要用 env->

ps:在linux下如果.c文件中用 “env->” 编译会找不到此结构,必须用“(*env)->”,或者改成.cpp文件,以 c++的方式来编译。

以下是两者的区别:

jni.h中

struct JNINativeInterface_;

struct JNIEnv_;

#ifdef __cplusplus
typedef JNIEnv_ JNIEnv;
#else
typedef const struct JNINativeInterface_ *JNIEnv;
#endif

/*
* We use inlined functions for C++ so that programmers can write:
*
* env->FindClass("java/lang/String")
*
* in C++ rather than:
*
* (*env)->FindClass(env, "java/lang/String")
*
* in C.
*/

即C++中使用
env->FindClass("java/lang/String")


C中使用

(*env)->FindClass(env, "java/lang/String")

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

分享: