110
技術社區[雲棲]
Jni使用過程中出現 error: request for member 'FindClass' in something not a structure or union,解決辦法
原文:https://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
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")
如果是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")
最後更新:2017-04-02 06:51:59