SAX and JNI

I'm having problems using Java classes from C. I've managed to trace the problem as far as the SAX parser, but I have no idea why there's a problem at all.

With the -verbose:jni option on, there's a message:"Unable to read from file" and then the JVM stops (crashes actually.)

I create a VM as follows:

JavaVM* jvm;

JNIEnv* env;

JavaVMInitArgs args;

JavaVMOption options[3];

int ret;

args.version = JNI_VERSION_1_4;

args.nOptions = 3;

options[0].optionString = classPath;

options[1].optionString ="-verbose:jni";

options[2].optionString ="-Djavax.xml.transform.TransformerFactory=net.sf.saxon.TransformerFactoryImpl";

args.options = options;

args.ignoreUnrecognized = JNI_TRUE;

if ((ret = JNI_CreateJavaVM(&jvm, (void **)&env, &args)) < 0){

/* error */

}

classPath is just a char* that lists all the Jars the project uses. I wrote a Java main() to test my code and when you run it with the exact same classpath, it works.

The Java code that creates and starts the SAX parser looks like:

XMLHandler handler =new XMLHandler ();

SAXParserFactory factory = SAXParserFactory.newInstance();

SAXParser saxParser = factory.newSAXParser();

try{

saxParser.parse(f, handler);

}catch (java.io.IOException e){

e.printStackTrace ();

}catch (Exception e){

e.printStackTrace ();

}

Is there something about JNI that SAX stuff won't work with it?

Any help is greatly appreciated.

[2113 byte] By [matthewa] at [2007-10-3 4:28:45]
# 1
Well "Unable to read from file" tells me that the program cannot find the file to parse, isn't it?Do you use absolute path names in both you JNI and Java tests?
jfbrierea at 2007-7-14 22:31:44 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 2

D'oh!

The java test code that "worked" actually used the wrong file name so the file didn't exist so it didn't actually execute the broken code.

When I hard-code the absolute path to the file, I still get "Unable to read from file". So I guess the problem isn't with the JNI but somewhere else in my code.

Thanks.

matthewa at 2007-7-14 22:31:44 > top of Java-index,Java HotSpot Virtual Machine,Specifications...