JNI_CreateJavaVM returns JNI_ERR

D

dzikus_

Hello,
I have problem with following code:
...
JNIEnv *env;
JavaVM *jvm;
JavaVMInitArgs vm_args;

vm_args.version = JNI_VERSION_1_2;
vm_args.options = NULL;
vm_args.nOptions = 0;
vm_args.ignoreUnrecognized = JNI_TRUE;
res = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
...

unfortunately JNI_CreateJavaVM returns -1 (JNI_ERR).

I tried on WinXP using jdk1.3.1_19 and VC++ 2005.
jvm.dll is copied from jdk1.3.1_19\jre\bin\classic\ to working path,
jdk1.3.1_19\include\ and jdk1.3.1_19\include\win32 are added to include
path
jdk1.3.1_19\lib\jvm.lib is included while linking program,

Do you have any idea what else should i check?

Regards
Dominik
www.goryidoliny.freehost.pl
 
C

Chris Uppal

jvm.dll is copied from jdk1.3.1_19\jre\bin\classic\ to working path,

You may have other problems, but that will cause JNI_CreateJavaVM() to fail all
by itself. You have to ensure that your outer program is loading the JVM.DLL
from the right place, not move the DLL.

I prefer to use an explicit call to the Win32 LoadLibrary() function myself
(I've posted example code here before -- Google should find it). Or you could
set the %Path% to include the directory containing the JVM.DLL -- that may
sound easier but is probably more messing around in the long run.

-- chris
 
D

dzikus_

I thing proper jvm.dll is loaded , becouse:
1) I see it indebugger information about loaded dll's:
... Loaded 'C:\dschaefer\workspace\jni\jvm.dll', No symbols loaded
....
2) when I delete dll from project directory program does not run
anymore.

Has anybody any other ideas?

Regards
Dominik
 
G

Gordon Beaton

I thing proper jvm.dll is loaded , becouse:
1) I see it indebugger information about loaded dll's:
... Loaded 'C:\dschaefer\workspace\jni\jvm.dll', No symbols loaded
...
2) when I delete dll from project directory program does not run
anymore.

Has anybody any other ideas?

Yes. Listen to the advice you've been given. Do not move the jvm.dll
from the rest of the JVM. It is dependent on other files there.

/gordon
 
D

dzikus_

Do not move the jvm.dll from the rest of the JVM. It is dependent on other files there.

This was the cause of my problem.
I have added to the PATH environment variable path
c:\Java\jdk1.3.1_19\jre\bin\classic\
and now CreateJavaVM is working OK :)

Thanks a lot for help
Best regards
Dominik
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,961
Messages
2,570,131
Members
46,689
Latest member
liammiller

Latest Threads

Top