Another error creating JVM through JNI

Discussion in 'Java' started by Tim, Feb 13, 2006.

  1. Tim

    Tim Guest

    I notice that there is another poster with a similar problem to mine,
    but he's on Unix and I am on Windows, and I think there may be a
    setup/config problem, so I am starting a new thread

    I am also getting an error creating the JVM, I am using j2sdk1.4.2_04
    with MSDEV 6.0 and have cut'n'pasted about three different pieces of
    sample code ( I won't post loads of code here) from working examples
    found on the web, they all fail on the call to JNI_CreateJavaVM with an
    error code of -1

    I am wondering is there are any common setup problems, perhaps having
    dlls in the wrong place of environment variables set wrongly, that
    might be a cause of this problem?


    Here is an example of one code sample I tried that did not work.
    Incidentally if I set the version wrong, I get a different error code
    (-3, which is to indicate wrong version)

    jint ret;
    JavaVM* jvm;
    JNIEnv* env;
    JavaVMInitArgs args;
    JavaVMOption options[1];

    args.version = JNI_VERSION_1_2;
    args.nOptions = 1;
    options[0].optionString = "-Djava.class.path=c:\\";
    args.options = options;
    args.ignoreUnrecognized = JNI_FALSE;

    ret = JNI_CreateJavaVM(&jvm, (void **)&env, &args);
     
    Tim, Feb 13, 2006
    #1
    1. Advertising

  2. On 13 Feb 2006 01:46:48 -0800, Tim wrote:
    > I am wondering is there are any common setup problems, perhaps
    > having dlls in the wrong place of environment variables set wrongly,
    > that might be a cause of this problem?


    The JVM DLL's must be in your PATH, or the program will fail to load
    them (and you will be unable to create the JVM).

    /gordon

    --
    [ do not email me copies of your followups ]
    g o r d o n + n e w s @ b a l d e r 1 3 . s e
     
    Gordon Beaton, Feb 13, 2006
    #2
    1. Advertising

  3. Tim

    Tim Guest

    Thanks Gordon -you set me thinking on the right lines; I had placed the
    JVM.dll in my project directory, so it was being loaded OK, but it
    seems it *has* to run from its default location. So I removed my copy
    of the dll and put the correct one on ther path and now it's working

    Tim
     
    Tim, Feb 13, 2006
    #3
  4. Tim

    Chris Uppal Guest

    Gordon Beaton wrote:

    > The JVM DLL's must be in your PATH, or the program will fail to load
    > them (and you will be unable to create the JVM).


    Or you can load the DLL explicitly by its filename. That's the approach I
    favour myself and recommend to others.

    I've posted code for that more than once, if the OP wants it then Goodle should
    provide.

    -- chris
     
    Chris Uppal, Feb 13, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kevin Hooke

    Re: Handling both MS JVM and Sun JVM

    Kevin Hooke, Aug 26, 2003, in forum: Java
    Replies:
    2
    Views:
    911
  2. Lasse
    Replies:
    1
    Views:
    739
    Jon A. Cruz
    Jan 5, 2004
  3. vasanth
    Replies:
    0
    Views:
    2,780
    vasanth
    Jan 25, 2005
  4. vasanth
    Replies:
    0
    Views:
    640
    vasanth
    Jan 25, 2005
  5. Bruce
    Replies:
    2
    Views:
    4,091
    Vitaly
    Feb 13, 2006
Loading...

Share This Page