compiled, but run: can't create JVM, using jdk1.3.1, version problem ?
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   ruilin_yang
Posted On:   Monday, April 7, 2003 09:59 PM

I am calling java classes from c++. I got a code sample which compiled. When I run it I get: can't create JVM and "The instruction at '0x0040127a' referenced memory at '0x00000000'. The memory could not be 'read'. I am using jdk1.3.1 if the code does not compatable with jni version ? or jvm.dll ? or jvm.lib ? I do not have a clue ! Here is my code please correct it if you see something is not right. I really stucked. Please help Thanks for your attention. Ruilin -------------------- #include "jni.h" #include #ifdef _WIN32 #define PATH_SEPARATOR ';' #else /* UNIX */ #define PATH_SEPARATOR ':' #endif #define   More>>

I am calling java classes from c++. I got a code sample which compiled. When I run it I get: can't create JVM and "The instruction at '0x0040127a' referenced memory at '0x00000000'. The memory could not be 'read'.

I am using jdk1.3.1 if the code does not compatable with jni version ? or jvm.dll ? or jvm.lib ? I do not have a clue !

Here is my code please correct it if you see something is not right.

I really stucked. Please help

Thanks for your attention.

Ruilin
--------------------
#include "jni.h"
#include

#ifdef _WIN32
#define PATH_SEPARATOR ';'
#else /* UNIX */
#define PATH_SEPARATOR ':'
#endif

#define USER_CLASSPATH "." /* where MainFrame.class is */

// user classpath


main() {
JNIEnv *env;
JavaVM *jvm;
// JDK1_1InitArgs vm_args;
JavaVMInitArgs vm_args;
jint res;
jclass cls;
jmethodID mid;
jstring jstr;
jobjectArray args;
char classpath[1024];

printf("
### welcome to the testprogram ###

");

JavaVMOption options[1];
options[0].optionString = "-Djava.class.path=.";
vm_args.options = options;
vm_args.nOptions = 0;
vm_args.ignoreUnrecognized = 1;

vm_args.version = JNI_VERSION_1_2;

vm_args.version = 0x00010001;
JNI_GetDefaultJavaVMInitArgs(&vm_args);

/* Append USER_CLASSPATH to the end of default system class path */
// sprintf(classpath, "%s%c%s",
// vm_args.classpath, PATH_SEPARATOR, USER_CLASSPATH);
// vm_args.classpath = classpath;

/* Create the Java VM */
res = JNI_CreateJavaVM(&jvm,(void**)&env,&vm_args);
if (res < 0) {
fprintf(stderr, "jni: Can't create Java VM
");
// exit(1);
}

cls = env->FindClass("MainFrame");
if (cls == 0) {
fprintf(stderr, "jni: Can't find MainFrame class
");
// exit(1);
}

mid = env->GetStaticMethodID(cls, "main", "([Ljava/lang/String;)V");
if (mid == 0) {
fprintf(stderr, "jni: Can't find MainFrame.main
");
// exit(1);
}

jstr = env->NewStringUTF(" from C!");
if (jstr == 0) {
fprintf(stderr, "jni: Out of memory
");
// exit(1);
}
args = env->NewObjectArray(1, env->FindClass("java/lang/String"), jstr);
if (args == 0) {
fprintf(stderr, "jni: Out of memory
");
// exit(1);
}
env->CallStaticVoidMethod(cls, mid, args);

jvm->DestroyJavaVM();

return 0;
}

   <<Less
About | Sitemap | Contact