Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Calling Java from C++ Frame not in module

Calling Java from C++ Frame not in module

Scheduled Pinned Locked Moved C / C++ / MFC
c++javatutorialcomtesting
1 Posts 1 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Valentinor
    wrote on last edited by
    #1

    I read this tutorial about how you can use Java inside your C++ project and I wanted to do some testing with it, but without changing anything in the project (only the path to /include and /win32 to my specific system) I'm getting the following exception: [^] [^] There are no errors in the project. Running a debug the error occurs at this line:

    jint rc = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);

    Source:

    // Example 2 of JNI invocation.
    // The java environment is prepared. Errors are reported.
    // Call to a simple static java methods
    // License: ZLIB license (see license.txt)
    // (c) Copyright 2015 by cth027

    #include #include int main()
    {
    using namespace std;

    JavaVM \*jvm;				// Pointer to the JVM (Java Virtual Machine)
    JNIEnv \*env;				// Pointer to native interface
    
    //==================== prepare loading of Java VM ============================
    
    JavaVMInitArgs vm\_args;                        // Initialization arguments
    JavaVMOption\* options = new JavaVMOption\[1\];   // JVM invocation options
    options\[0\].optionString = "-Djava.class.path=.";   // where to find java .class
    vm\_args.version = JNI\_VERSION\_1\_6;             // minimum Java version
    vm\_args.nOptions = 1;                          // number of options
    vm\_args.options = options;
    vm\_args.ignoreUnrecognized = false;     // invalid options make the JVM init fail
    
    //================= load and initialize Java VM and JNI interface ===============
    
    jint rc = JNI\_CreateJavaVM(&jvm, (void\*\*)&env, &vm\_args);  // YES !!
    delete\[\] options;    // we then no longer need the initialisation options. 
    
    //========================= analyse errors if any  ==============================
    // if process interuped before error is returned, it's because jvm.dll can't be 
    // found, i.e.  its directory is not in the PATH. 
    
    if(rc != JNI\_OK) {
    	if(rc == JNI\_EVERSION)
    		cerr << "FATAL ERROR: JVM is oudated and doesn't meet requirements" << endl;
    	else if(rc == JNI\_ENOMEM)
    		cerr << "FATAL ERROR: not enough memory for JVM" << endl;
    	else if(rc == JNI\_EINVAL)
    		cerr << "FATAL ERROR: invalid ragument for launching JVM" << endl;
    	else if(rc == JNI\_EEXIST)
    
    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups