安卓 JNI C++中的"Not declared in this scope"错误

"Not declared in this scope" error in Android JNI C++

本文关键字:in this scope 错误 declared Not JNI C++ 中的 安卓      更新时间:2023-10-16

我有这个使用C++的JNI代码。

#include <eigenfaces_jni.h>
#include <opencv2/core/core.hpp>
#include <opencv2/contrib/contrib.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <string>
#include <vector>
#include <iostream>
#include <fstream>
#include <sstream>

using namespace std;
using namespace cv;

JNIEXPORT jstring JNICALL Java_com_example_facedetector_FaceTracker_nativeCreateObject
  (JNIEnv *env, jclass, jstring JFileDir){
// These vectors hold the images and corresponding labels.
    vector<Mat> images;

const char *str = env->GetStringUTFChars(jFileDir, NULL);
const char *buf;
/*Releasing the Java String once you have got the C string
      is very important!!!*/
      env->ReleaseStringUTFChars(jFileDir, str);
            Mat im = imread(jFileDir);
            if (im.empty())
                {
                    cout << "Cannot load image!" << endl;
                    buf = "Can load image";
                }
            else{
                buf = "Cannot load image";
            }
            return env->NewStringUTF("Hello");
}

但是,在

const char *str = env->GetStringUTFChars(jFileDir, NULL);

其中指出

 - Symbol 'jFileDir' could not be resolved
- 'jFileDir' was not declared in this scope
- Invalid arguments ' Candidates are: const char * GetStringUTFChars(_jstring *, unsigned 
 char *) '

已尝试此链接中的解决方案 无法解析类型"std::string"。仍然不工作。任何解决此问题的帮助将不胜感激。谢谢。

您已经声明了一个名为 JFileDir 的函数参数,但没有声明名为 jFileDir 的函数参数。C++区分大小写。

好吧,由于我没有足够的声誉点来表扬,所以我必须写这个作为答案。检查你的函数参数列表(JNIEnv *env,jclass,jstring JFileDir(,jclass是关于什么的,我觉得这里缺少一些东西。