Can't initialize jni4net

2,843 views
Skip to first unread message

Michael Ivanov

unread,
Nov 22, 2010, 1:58:19 PM11/22/10
to jni4net
Hi, I have found jni4net extremely useful, and it works well on my
machine. Thank you for developing and supporting it. I am having
trouble getting it to work on another developer's machine, even just
using the sample projects. I sent him a project which is basically
the helloWorldFromCLR sample project, with the Verbose and VeryVerbose
options set to True, hoping to get more detailed info. Here is the
output when he tries to run this or any of the other sample projects.

Unhandled Exception: net.sf.jni4net.jni.JNIException: Can't initialize
jni4net. (32bit vs 64bit JVM vs CLR ?) --->
System.InvalidCastException: Unable to cast object of type
'pf_sbyte_IntPtr_IntPtr_pjvalue' to type 'CallBooleanMethod'.
at net.sf.jni4net.jni.MethodWrapper.GetDelegateForFunctionPointer[T]
(IntPtr ptr, T& res)
at net.sf.jni4net.jni.JNIEnv.InitMethods()
at net.sf.jni4net.jni.JNIEnv..ctor(IntPtr native)
at net.sf.jni4net.jni.JNI.CreateJavaVM(JavaVM& jvm, JNIEnv& env,
Boolean attachIfExists, String[] options)
at net.sf.jni4net.Bridge.CreateJVM()
--- End of inner exception stack traces ---
at net.sf.jni4net.Bridge.CreateJVM()
at net.sf.jni4net.Bridge.CreateJVM(BridgeSetup setup)
at helloWorldFromCLR.Program.Main()

Any ideas for diagnosing this problem?

As far as we can tell the 32bit vs 64bit hint is incorrect. Here is
the output from "java -version"

java version "1.6.0_22"
Java(TM) SE Runtime Environment (build 1.6.0_22-b04)
Java HotSpot(TM) Client VM (build 17.1-b03, mixed mode, sharing)


And here are some of the system properties:

OS Name Microsoft Windows XP Professional
Version 5.1.2600 Service Pack 3 Build 2600
OS Manufacturer Microsoft Corporation
System Manufacturer Dell Inc.
System Model Latitude D830
System Type X86-based PC
Processor x86 Family 6 Model 23 Stepping 6 GenuineIntel
~2493 Mhz
BIOS Version/Date Dell Inc. A11, 4/3/2008
SMBIOS Version 2.4
Windows Directory C:\WINDOWS
System Directory C:\WINDOWS\system32
Hardware Abstraction Layer Version = "5.1.2600.5512 (xpsp.
080413-2111)"
Total Physical Memory 2,048.00 MB
Available Physical Memory 481.91 MB
Total Virtual Memory 2.00 GB
Available Virtual Memory 1.95 GB
Page File Space 3.84 GB
Page File C:\pagefile.sys

Thank you

Nick Sklabinsky

unread,
Nov 22, 2010, 2:16:32 PM11/22/10
to jni4net
Hi,

32 vs 64 error is a real bugger, but so far it seems to be entirely
correct.
Make sure that you are using a 32 JRE on 32-bit OS and 64 on 64.
Remember that in case you're using a 32-bit browser on 64-bit OS, you
will still get 32-bit JRE from java.com! I actually had to download 64-
bit JDK in order to get the correct JRE.
You can also specify a path to the correct Java run-time when
initializing JNI4NET.

Pavel Šavara

unread,
Nov 22, 2010, 2:30:23 PM11/22/10
to jni...@googlegroups.com
Hi Michael,

This is interesting:


> 'pf_sbyte_IntPtr_IntPtr_pjvalue' to type 'CallBooleanMethod'.

The pointer to JNI method CallBooleanMethod is received from call to
JNI_CreateJavaVM on jvm.dll.
The jni4net is trying to find the DLL in JAVA_HOME
http://code.google.com/p/jni4net/source/browse/trunk/jni4net.n/src/jni/JNI.cs

I never seen this before, so I'm just guessing:
- JAVA_HOME is incorrect
- or wrong jvm.dll is on PATH and wins the binding
- something is corrupted, memory or files

> As far as we can tell the 32bit vs 64bit hint is incorrect.

It's just hint.


BTW: what version of CLR your friend have ?

Cheers
Pavel

Michael Ivanov

unread,
Nov 22, 2010, 2:32:12 PM11/22/10
to jni4net
Thanks for your response. As you can see in the system properties,
this is a 32-bit OS. Even trying to install the 64-bit JDK does not
work in my attempts to test this hypothesis.

Pavel Šavara

unread,
Nov 22, 2010, 3:00:01 PM11/22/10
to jni...@googlegroups.com
> 32 vs 64 error is a real bugger, but so far it seems to be entirely
> correct.

Hi Nick, hi all

I thought what would be most appropriate message for it. The current
one might be misleading.

My current idea is
"Can't initialize jni4net. Talk to your software vendor or see
http://jni4net.sf.net/troubleshoot.shtml"
What you guys think ?

Also we could possibly improve the JVM detection. Find proper one in
"Program Files" vs "Program Files (x86)"is not that difficult.
See FindJvmDir()
http://code.google.com/p/jni4net/source/browse/trunk/jni4net.n/src/jni/JNI.cs
Also as far as I can remember the inner exception is some specific
type, when we hit 64 vs 32, we could do better there.

Shall we autofix wrong JAVA_HOME ? I don't think so, but would like to
hear from folks.

Anyone interested to contribute it ?

Thanks
Pavel

Michael Ivanov

unread,
Nov 22, 2010, 4:11:41 PM11/22/10
to jni4net
Thanks for your suggestions. Setting JAVA_HOME (was not set before)
did not fix this problem. The following versions of the .Net
framework are installed: 1.0, 2.0, 3.0, 3.5 and 4. I instructed the
developer to find out which jvm.dll is being loaded using Process
Monitor. I will post back when I get that info.

Mike

On Nov 22, 11:30 am, Pavel Šavara <pavel.sav...@gmail.com> wrote:
> Hi Michael,
>
> This is interesting:
>
> > 'pf_sbyte_IntPtr_IntPtr_pjvalue' to type 'CallBooleanMethod'.
>
> The pointer to JNI method CallBooleanMethod is received from call to
> JNI_CreateJavaVM on jvm.dll.
> The jni4net is trying to find the DLL in JAVA_HOMEhttp://code.google.com/p/jni4net/source/browse/trunk/jni4net.n/src/jn...

Nikolay Sklabinsky

unread,
Nov 24, 2010, 2:12:54 PM11/24/10
to jni...@googlegroups.com
I would not say that this error message is misleading - as I noted earlier,
I am all too familiar with it and so far it was always correct.
Pavel of course knows better, for I do not know how exactly JNI4NET works
and who knows what else might send this error message.
Anyway, Pavel, your latest message variant does not change much; this
reference to vendor is not particularly helpful either, imho.

Improved JVM detection would certainly be a boon. I might even volunteer.

And let's not fix wrong JAVA_HOME; not our problem - and probably Oracle/Sun
should take care of it.

Hi Nick, hi all

Thanks
Pavel

--
You received this message because you are subscribed to
jni...@googlegroups.com
http://groups.google.com/group/jni4net?hl=en-GB?hl=en-GB
http://jni4net.sf.net/

Reply all
Reply to author
Forward
0 new messages