I want to hide my java code.So i crate java class inside jni folder and trying to call that class method.But I'm getting ClassNotFound exception while find class in c++.is it possible?.This is my first ndk project.so i don't know about this.Please tell me solution.
this is my c++ code
#include <jni.h>
#include <string.h>
#include <iostream>
using namespace std;
extern "C" JNIEXPORT jstring JNICALL
Java_com_example_sohamsaa_ndktest_MyNativeClass_startRecord(JNIEnv* env,jobject obj){
jclass cls2 = env->FindClass("jni/MyTest");//here i'm getting classnotfound exception
if(cls2 == NULL) {
cerr << "ERROR: class not found !";
}
else {
cout << "Class MyTest found" << endl;
jmethodID mid = env->GetStaticMethodID(cls2, "mymain", "()V");
if(mid == NULL)
cerr << "ERROR: method void mymain() not found !" << endl;
else {
env->CallStaticVoidMethod(cls2, mid);
cout << endl;
}
}
return (*env).NewStringUTF("Hi siddharthan");
}
this is my java class
public class MyTest {
public static void mymain() {
System.out.println("Hello, World in java from mymain");
}
}
In theory, yes you could put a class in the JNI folder. However, it would not achieve the result that you desire:
Basically, it won't work. You cannot hide the code if you want the user's device to be able to run it.
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.