Android将“.c”后缀名改为“.cpp”时java调用native失败及“error: base operand of '->' has non-poin[转]
2012-04-20 21:17
477 查看
现象:“.c”后缀名改为“.cpp”时java调用native失败 。
解决: 加入“ extern "C" ”。
现象:“error: base operand of '->' has non-pointer type '_JNIEnv'”错误。
解决: 将“(*env)->NewStringUTF(env, "HelloWorld from JNI !");”改为“env->NewStringUTF("HelloWorld from JNI !")”。
例子:
Cpp代码
#include <stdio.h>
#include <string.h>
#include <android/log.h>
#include <jni.h>
#ifdef __cplusplus
extern "C"
{
#endif
jint Java_com_duicky_MainActivity_add(JNIEnv* env, jobject thiz, jint x, jint y)
{
//该方法为打印的方法
__android_log_print(ANDROID_LOG_INFO, "JNIMsg", "Get Param: x=%d y=%d ", x, y);
int iRet = x + y;
return iRet;
}
jstring Java_com_duicky_MainActivity_getString(JNIEnv* env, jobject thiz)
{
jstring strRet = env->NewStringUTF("HelloWorld from JNI !");
return strRet;
}
#ifdef __cplusplus
}
#endif
解决: 加入“ extern "C" ”。
现象:“error: base operand of '->' has non-pointer type '_JNIEnv'”错误。
解决: 将“(*env)->NewStringUTF(env, "HelloWorld from JNI !");”改为“env->NewStringUTF("HelloWorld from JNI !")”。
例子:
Cpp代码
#include <stdio.h>
#include <string.h>
#include <android/log.h>
#include <jni.h>
#ifdef __cplusplus
extern "C"
{
#endif
jint Java_com_duicky_MainActivity_add(JNIEnv* env, jobject thiz, jint x, jint y)
{
//该方法为打印的方法
__android_log_print(ANDROID_LOG_INFO, "JNIMsg", "Get Param: x=%d y=%d ", x, y);
int iRet = x + y;
return iRet;
}
jstring Java_com_duicky_MainActivity_getString(JNIEnv* env, jobject thiz)
{
jstring strRet = env->NewStringUTF("HelloWorld from JNI !");
return strRet;
}
#ifdef __cplusplus
}
#endif
相关文章推荐
- Android将“.c”后缀名改成“.cpp”时java调用native失败及“error: base operand of '->' has non-poin
- (Android jni) error: base operand of '->' has non-pointer type '_JNIEnv'
- 使用AS编译时,报Error:Execution failed for task ':app:transformClassesWithDexForDebug'. > com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concur
- Android导入项目报错Error:Execution failed for task ':app:transformNativeLibsWithMergeJniLibsForDebug'. > M
- JNI: error: base operand of ‘->’ has non-pointer type ‘JNIEnv’
- Error:Execution failed for task ':andBase:compileReleaseJavaWithJavac'. > Compilation failed;
- Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'. > com.android.bui
- JNI错误之:error: base operand of '->' has non-pointer type '_JNIEnv'
- android的两层架构--.cpp -> .java
- Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'. > com.android.bui
- https://github.com/havlenapetr/android_frameworks_base/blob/froyo-sgs/native/video/jni/surface.cpp
- android中java和JS互相调用,Web Console: Uncaught TypeError: Object [object Object] has no method
- Android Studio clean 时产生 Error:Execution failed for task ':app:mockableAndroidJar' > java.lang.NullP
- Android 调用.so包时报错:No implementation found for native Lxxx, java.lang.UnsatisfiedLinkError: XXX时的解决办法(转)
- Android 开发系列(3) - native代码调用java代码出现attempt using stale local reference错误及解决办法
- error: base operand of ‘->’ has non-pointer type ‘JNIEnv’
- [Android] 解决Release版本HWPFDocument写doc文件失败java.lang.ExceptionInInitializerError
- Error:Execution failed for task ':app:proguardRelease'.> java.io.IOException: Can't read [D:\android
- Android webview js 调用java方法报错"Uncaught TypeError: Object [object Object] has no method xx