Home > Archive > Java Help > May 2004 > Simple JNI program fails
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Simple JNI program fails
|
|
| Steve Dussinger 2004-05-20, 10:31 pm |
| Extracting the following C++ code (with some minor mods) from other
posts in this group, I was hoping to at least be able to create a JVM
and grab a class which is pretty much guaranteed to exist. Well, I
can't seem to make the thing work.
Running under the debugger, I can see the JVM get created, but when I
try to find the System class, I get a zero response.
Now near as I can tell, System should always be available, if the JVM
has been initialized at all, but I can't seem to get it to work.
Anyone have any ideas?
Code follows----------------------------
JNIEnv *env;
JavaVM *jvm;
JavaVMInitArgs vm_args;
JavaVMOption options[1];
jint res;
jclass cls;
jmethodID mid;
jstring jstr;
jobjectArray args;
long status;
options[0].optionString = "-Djava.class.path=.";
memset(&vm_args, 0, sizeof(vm_args));
vm_args.version = JNI_VERSION_1_4;
vm_args.nOptions = 1;
vm_args.options = options;
status = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
if(status == JNI_ERR) {
printf("Error creating VM\n");
}
cls = env->FindClass("System");
if (cls == 0) {
fprintf(stderr, "Can't find System class\n");
exit(1);
}
-----------------------------------
BTW, it's running on Windows XP, the C++ is written using Visual
Studio.NET 2003 (v 7.1) using the Sun jdk1.4.2_04 VM...
Thanx for any help...
--Steve
| |
| Gordon Beaton 2004-05-21, 6:31 am |
| On 20 May 2004 18:53:18 -0700, Steve Dussinger wrote:
> Extracting the following C++ code (with some minor mods) from other
> posts in this group, I was hoping to at least be able to create a
> JVM and grab a class which is pretty much guaranteed to exist. Well,
> I can't seem to make the thing work.
>
> Running under the debugger, I can see the JVM get created, but when
> I try to find the System class, I get a zero response.
[...]
> cls = env->FindClass("System");
Try this instead:
cls = env->FindClass("java/lang/System");
if (!cls) {
if (env->ExceptionOcurred()) {
env->ExceptionDescribe();
}
}
/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
|
|
|
|
|