error: 'jstringToString' was not declared in this scope
2014-10-23 16:04
519 查看
============问题描述============
刚接触写个jni代码,出现一个问题“error: 'jstringToString' was not declared in this scope”
请问这是为嘛呢?不胜感激..
错误如下:
[armeabi] Compile++ thumb: Inotify <= Inotify.cpp
jni/Inotify.cpp: In function 'void Java_lab_sodino_inotifylab_MainActivity_watch(JNIEnv*, jobject, jstring)':
jni/Inotify.cpp:16:49: error: 'jstringToString' was not declared in this scope
make: *** [obj/local/armeabi/objs/Inotify/Inotify.o] Error 1
代码如下:
============解决方案1============
char* jstringToString(JNIEnv* env, jstring jstr) 没有提前声明吧,把这个函数移到 main 的前面去呢
============解决方案2============
char* jstringToString(JNIEnv* env, jstring jstr); 在最上面生明一下
============解决方案3============
主要是 c++编译的问题,编译器需要提前知道有哪些方法可以被调用,所以你可以选择提供函数声明,或者将函数提前到调用之前,否则编译器在编译到这里的时候,他发现没有对应的方法,就会报错的
具体信息你可以搜一下 c++ 的函数声明
刚接触写个jni代码,出现一个问题“error: 'jstringToString' was not declared in this scope”
请问这是为嘛呢?不胜感激..
错误如下:
[armeabi] Compile++ thumb: Inotify <= Inotify.cpp
jni/Inotify.cpp: In function 'void Java_lab_sodino_inotifylab_MainActivity_watch(JNIEnv*, jobject, jstring)':
jni/Inotify.cpp:16:49: error: 'jstringToString' was not declared in this scope
make: *** [obj/local/armeabi/objs/Inotify/Inotify.o] Error 1
代码如下:
#include <jni.h> #include <string.h> #include <android/log.h> #define TAG "ANDROID_LAB" // 这个是自定义的LOG的标识 #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,TAG ,__VA_ARGS__) // 定义LOGD类型 #ifdef __cplusplus extern "C" { #endif JNIEXPORT void JNICALL Java_lab_sodino_inotifylab_MainActivity_watch (JNIEnv * env, jobject thiz, jstring pathWatch){ char *char_pathWatch = NULL; char_pathWatch = jstringToString(env, pathWatch); LOGD("watch path=%s", char_pathWatch); } char* jstringToString(JNIEnv* env, jstring jstr) { char* rtn = NULL; jclass clsstring = env->FindClass("java/lang/String"); jstring strencode = env->NewStringUTF("utf-8"); jmethodID mid = env->GetMethodID(clsstring, "getBytes", "(Ljava/lang/String;)[B"); jbyteArray barr = (jbyteArray) env->CallObjectMethod(jstr, mid, strencode); jsize array_lenth = env->GetArrayLength(barr); jbyte* ba = env->GetByteArrayElements(barr, JNI_FALSE); if (array_lenth > 0) { rtn = (char*) malloc(array_lenth + 1); memcpy(rtn, ba, array_lenth); rtn[array_lenth] = 0; } env->ReleaseByteArrayElements(barr, ba, 0); return rtn; } #ifdef __cplusplus } #endif
============解决方案1============
char* jstringToString(JNIEnv* env, jstring jstr) 没有提前声明吧,把这个函数移到 main 的前面去呢
============解决方案2============
char* jstringToString(JNIEnv* env, jstring jstr); 在最上面生明一下
============解决方案3============
主要是 c++编译的问题,编译器需要提前知道有哪些方法可以被调用,所以你可以选择提供函数声明,或者将函数提前到调用之前,否则编译器在编译到这里的时候,他发现没有对应的方法,就会报错的
具体信息你可以搜一下 c++ 的函数声明
相关文章推荐
- error:inet_addr() was not declared in this scope
- error: '_localtime_not_threadsafe_' was not declared in this scope
- 文档源代码opencv 中的错误error: ‘SurfFeatureDetector’ was not declared in this scope
- error: 'memcpy' was not declared in this scope的解决
- error: 'UINT64_C' was not declared in this scope
- error: ‘closesocket’ was not declared in this scope
- error: ‘exit’ was not declared in this scope
- error: 'system' was not declared in this scope
- linux 编译ffmpeg 出错:error: 'UINT64_C' was not declared in this scope
- error: ‘exit’ was not declared in this scope 的解决方法
- error: ‘alarm’ was not declared in this scope 解决
- error: ‘errno’ was not declared in this scope
- opencv 中的错误error: ‘SurfFeatureDetector’ was not declared in this scope
- linux 编译ffmpeg 出错:error: 'UINT64_C' was not declared in this scope
- Solution to error: ‘_1’ was not declared in this scope under C++11 standard
- error: 'memcpy' was not declared in this scope的解决 [转]
- mmseg 安装错误 error: ’strncmp’ was not declared in this scope
- error: ‘memcpy’ was not declared in this scope 解决
- 关于error: ‘htons’ was not declared in this scope
- error: `cout' was not declared in this scope