开发者

JNI FindClass java.lang.ClassNotFoundException

开发者 https://www.devze.com 2022-12-18 09:08 出处:网络
I am currently writing some JNI code to call a class within my JAVA program. I have done this successfully already with static methods within a class.

I am currently writing some JNI code to call a class within my JAVA program. I have done this successfully already with static methods within a class.

Currently, when I use:

jclass proc_jclass = env->FindClass("example/io/struct/JavaClass");

It crashes the JVM with:

java.lang.ClassNotFoundEx开发者_如何转开发ception.<init>(Ljava/lang/String;)V+3

I have already tried defining class path locations, to no avail. Any help would be greatly appreciated.

Thanks.


I found the answer myself. The issue was solved by moving the FindClass to directly underneath the JNIEXPORT method. As bmargulies stated it may have been caused by the env pointer being modified. By moving it to the top of the method this was avoided. Looking at the code it still not clear what was causing the problem but ill report back when I find out. In addition top tip use a variable i.e:

env->FindClass(str_class);

str_class was used to define the ClassPath so that you can quickly test what classes are accessible without re-compliing. - I know its obvious, but does save time when debugging.

0

精彩评论

暂无评论...
验证码 换一张
取 消