I want to call a Java method from C++. I've followed other examples I've found, but I keep getting the error:
GetMethodID: method not found: Lcom/test/ndk/GL2JNIActivity;.GetFiles:(L/java/lang/String;Ljava/lang/String;Z;)V
What am I doing wrong here? I suspect my method signature string is wrong for env->GetMethodID(), but it looks like it's correct from other examples I've seen.
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;
}
}
Java:
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());
}
}
}
You should replace
jmethodID mid = env->GetMethodID(clazz, "GetFiles", "(Ljava/lang/String;Ljava/lang/String;Z;)V");
by
jmethodID mid = env->GetMethodID(clazz, "GetFiles", "(Ljava/lang/String;Ljava/lang/String;Z)V");
because last parameter is a boolean that is not a fully qualified class but a basic type signature so no ;
is needed.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.