• Android将“.c”后缀名改为“.cpp”时java调用native失败及“error: base operand of '>' has nonpoin[转]


    现象“.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代码  收藏代码
    1. #include <stdio.h>  
    2. #include <string.h>  
    3. #include <android/log.h>  
    4. #include <jni.h>  
    5.   
    6. #ifdef __cplusplus  
    7. extern "C"  
    8. {  
    9. #endif  
    10.   
    11. jint Java_com_duicky_MainActivity_add(JNIEnv* env, jobject thiz, jint x, jint y)  
    12. {  
    13.     //该方法为打印的方法  
    14.     __android_log_print(ANDROID_LOG_INFO, "JNIMsg""Get Param:  x=%d y=%d ", x, y);  
    15.   
    16.     int iRet = x + y;  
    17.     return iRet;  
    18. }  
    19.   
    20. jstring Java_com_duicky_MainActivity_getString(JNIEnv* env, jobject thiz)  
    21. {  
    22.     jstring strRet = env->NewStringUTF("HelloWorld from JNI !");  
    23.     return strRet;  
    24. }  
    25.   
    26. #ifdef __cplusplus  
    27. }  
    28. #endif  

     

  • 相关阅读:
    学习笔记|数组的扩展
    javascript日期 时间处理类库
    v-if v-for同时使用 解决eslint报错问题
    跳出foreach循环
    live-player live-pusher惨案
    TypeError: Object(…) is not a function
    实现垂直水平居中的方法
    面试时候遇到的笔试题
    ajax跨域
    Bootstrap响应式相关
  • 原文地址:https://www.cnblogs.com/afly/p/2459850.html
Copyright © 2020-2023  润新知