4

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.ClassNotFoundException.<init>(Ljava/lang/String;)V+3

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

Thanks.

2
  • 1
    is the name of your class really example.io.struct.JavaClass? What do you mean by 'crashes the JVM?' a hotspot crash? Have you stored away an env ptr that you weren't supposed to? Commented Jan 23, 2010 at 20:04
  • it isn't. Though it is similar. Yes the error is a hotspot crash. I have not modified the env pointer in anyway. Thanks Commented Jan 23, 2010 at 20:30

1 Answer 1

6

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Moving my jclass proc_jclass = env->FindClass(“example/my/class/JavaClass”); to the very first line in my JNI function fixed this issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.