 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Steve Dussinger Guest
|
Posted: Fri May 21, 2004 1:53 am Post subject: Simple JNI program fails |
|
|
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 VMn");
}
cls = env->FindClass("System");
if (cls == 0) {
fprintf(stderr, "Can't find System classn");
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
|
|
| Back to top |
|
 |
Gordon Beaton Guest
|
Posted: Fri May 21, 2004 9:23 am Post subject: Re: Simple JNI program fails |
|
|
On 20 May 2004 18:53:18 -0700, Steve Dussinger wrote:
| Quote: | 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.
|
[...]
| Quote: | 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
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|