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")

相关文章
|
5月前
|
小程序
小程序踩坑:Setting data field "xxxx" to undefined is invalid.
小程序踩坑:Setting data field "xxxx" to undefined is invalid.
82 0
|
21天前
runtime error: member access within misaligned address(力扣最常见错误之一)
runtime error: member access within misaligned address(力扣最常见错误之一)
19 0
|
5月前
SQLSTATE[42S02]: Base table or view not found: 1146 Table ‘thinkphp.test‘ don‘t exsit
SQLSTATE[42S02]: Base table or view not found: 1146 Table ‘thinkphp.test‘ don‘t exsit
90 0
|
1月前
|
SQL JSON Java
【bug日记】已解决:Invalid bound statement (not found): 找不到对应的Mapper映射类
【bug日记】已解决:Invalid bound statement (not found): 找不到对应的Mapper映射类
|
5月前
|
JSON 小程序 API
小程序踩坑-Setting data field "list" to undefined is invalid.
小程序踩坑-Setting data field "list" to undefined is invalid.
118 0
|
5月前
|
SQL Java 数据库连接
错误:FUNCTION simple_notebook.count does not exist.解决方法
错误:FUNCTION simple_notebook.count does not exist.解决方法
|
8月前
|
数据采集 缓存 Android开发
Assertion desc failed at libswscale/swscale_internal.h:674和ffmpeg的各种key+value
Assertion desc failed at libswscale/swscale_internal.h:674和ffmpeg的各种key+value
123 0
解决办法:找不到g_type_check_instance_cast
解决办法:找不到g_type_check_instance_cast
100 0
解决办法:对lzma_stream_decoder/lzma_code/lzma_end未定义的引用
解决办法:对lzma_stream_decoder/lzma_code/lzma_end未定义的引用
156 0
|
Java C语言 C++
JNI ERROR (app bug): local reference table overflow (max=512)
JNI ERROR (app bug): local reference table overflow (max=512)
262 0
JNI ERROR (app bug): local reference table overflow (max=512)