我想从 C++ 调用 Java 方法。我已经按照我找到的其他示例进行操作,但我不断收到错误消息:
GetMethodID: method not found: Lcom/test/ndk/GL2JNIActivity;.GetFiles:(L/java/lang/String;Ljava/lang/String;Z;)V
我在这里做错了什么?我怀疑我的方法签名字符串对于 env->GetMethodID() 是错误的,但从我见过的其他示例看来它是正确的。
C++:
namespace Resource
{
FileInfo *GetFiles(const char *path, const char *mask, bool directory)
{
JNIEnv *env = Android_JNI_GetEnv();
jstring jstr1 = env->NewStringUTF(path);
jstring jstr2 = env->NewStringUTF(mask);
fileInfos = NULL;
jclass clazz = env->FindClass("com/test/ndk/GL2JNIActivity");
jmethodID mid = env->GetMethodID(clazz, "GetFiles", "(Ljava/lang/String;Ljava/lang/String;Z;)V");
jobject obj = env->CallStaticObjectMethod(clazz, mid);
return fileInfos;
}
}
爪哇:
package com.test.ndk;
import java.io.File;
public class GL2JNIActivity extends Activity implements SensorEventListener {
public static void GetFiles(String sentPath, String mask, boolean directory)
{
String path = Environment.getExternalStorageDirectory().toString()+sentPath;
Log.d("Files", "Path: " + path);
File f = new File(path);
File file[] = f.listFiles();
Log.d("Files", "Size: "+ file.length);
for (int i=0; i < file.length; i++)
{
Log.d("Files", "FileName:" + file[i].getName());
GL2JNILib.AddFileToList(file[i].getName(), file[i].isDirectory());
}
}
}