Problem with FindClass

P

paco

Greetings everybody,
I am having all kind of problems with JNI...
First it seems that in order to start the VM machine I have to use an
absolute path to the VM machine. "C:\\Program
Files\\Java\\jre1.5.0\\bin\\client\\jvm" ...

Now my problem is that FindClass doesn't seem to work at all no matter
what class I try to find. I even tried to set an absolute path to be
sure it's not a path or a name thing.

Can anybody tell me what I am doing wrong ?
thanx in advance ...

jclass cls;
jint res=-1;
JNIEnv *pEnv = 0;
JavaVM *pJvm = 0;
LPFNCREATEJVM ProcAddCreateVM;
HINSTANCE hinstLib;
LPFNGETARG ProcAddGetArg;

JavaVMInitArgs vm_args;
JavaVMOption options[1];
options[0].optionString = "-verbose:jni";
vm_args.version = JNI_VERSION_1_2;
vm_args.options = options;
vm_args.nOptions = 1;
vm_args.ignoreUnrecognized = 0;

hinstLib = LoadLibrary("C:\\Program
Files\\Java\\jre1.5.0\\bin\\client\\jvm");
if (hinstLib != NULL)
{
ProcAddCreateVM = LPFNCREATEJVM (GetProcAddress(hinstLib,
"JNI_CreateJavaVM"));
ProcAddGetArg = LPFNGETARG
(GetProcAddress(hinstLib,"JNI_GetDefaultJavaVMInitArgs"));
if (ProcAddGetArg)
{
res = ProcAddGetArg(&vm_args);
if (ProcAddCreateVM != NULL)
{
res = ProcAddCreateVM(&pJvm, (void**)&pEnv, &vm_args);
}
}

FreeLibrary(hinstLib);
}
if (res < 0)
{
fprintf(stderr, "Can't create Java VM\n");
return -1;
}
jthrowable e;

cls = pEnv->FindClass("C:\\SyntagmaticAnalyzer");

//At this point : cls = 0 and got an Exception raised
e = pEnv->ExceptionOccurred();
if (e)
{
pEnv->ExceptionDescribe();
}
 
C

Chris Smith

cls = pEnv->FindClass("C:\\SyntagmaticAnalyzer");

//At this point : cls = 0 and got an Exception raised

You are passing C:\SyntagmaticAnalyzer as a class name; that's not a
legal class name. It looks like it's some kind of weird cross between a
package name and a file name, instead. If there's a file name on your
drive called "C:\SyntagmaticAnalyzer.class", then the class name ought
to be SyntagmaticAnalyzer (note that C:\ is part of a file name, and
isn't part of the name of the class; it doesn't belong here).

You then need to ensure that the classpath for the virtual machine
includes the directory "C:\".

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
P

paco

Hey there Chris and thank you much for the help!
Do you know how can I ensure my classpath for the Virtual machine ?

Paco
 
P

paco

Ok I set the classpath and then I called FindClass the way you said to
but it still returns 0x000
Here's the new code :

JNIEnv *pEnv = 0;
JavaVM *pJvm = 0;
LPFNCREATEJVM ProcAddCreateVM;
HINSTANCE hinstLib;
LPFNGETARG ProcAddGetArg;

JDK1_1InitArgs vm_args;
vm_args.version = JNI_VERSION_1_2;
vm_args.classpath =
"C:\\Source\\Mathematique\\prototypeAnalyzer\\analyzer\\engine";

hinstLib = LoadLibrary("C:\\Program
Files\\Java\\jre1.5.0\\bin\\client\\jvm");
if (hinstLib != NULL)
{
ProcAddCreateVM = LPFNCREATEJVM (GetProcAddress(hinstLib,
"JNI_CreateJavaVM"));
ProcAddGetArg = LPFNGETARG
(GetProcAddress(hinstLib,"JNI_GetDefaultJavaVMInitArgs"));
if (ProcAddGetArg)
{
res = ProcAddGetArg(&vm_args);
if (ProcAddCreateVM != NULL)
{
res = ProcAddCreateVM(&pJvm, (void**)&pEnv, &vm_args);
}
}
FreeLibrary(hinstLib);
}
if (res < 0)
{
fprintf(stderr, "Can't create Java VM\n");
return -1;
}
jthrowable e;

//Still returns 0 here ...
cls = pEnv->FindClass("SyntagmaticAnalyzer");
e = pEnv->ExceptionOccurred();
if (e)
{
pEnv->ExceptionDescribe();
}
 
C

Chris Smith

paco said:
vm_args.classpath =
"C:\\Source\\Mathematique\\prototypeAnalyzer\\analyzer\\engine";

You seem to be changing several things at once. The first rule of
troubleshooting is this: don't change more than one thing at the same
time. When you first posted, your class file seemed to be located at:

C:\SyntagmaticAnalyzer.class

If that's the case, then the classpath needs to be C:\ rather than the
long string you have above.

Please post the full path of the ".class" file. Also, is there a
package statement at the beginning of the source code for that class?

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,701
Latest member
XavierQ83

Latest Threads

Top