Invocation API: Almost there. Can call main(). Can't call foo().
I'm using the Invocation API to call Java from C, and am pleased to announce I've had some success. Woo hoo!Here's the Java program I'm using:
publicclass DeleteMe
{
publicstaticvoid main( String args[] )
{
System.out.println("DeleteMe A: main()" + args[0] );
}
publicstatic String foo( String arg )
{
System.out.println("DeleteMe A: foo()" + arg);
return"Hello World";
}
}
My C code finds the DeleteMe class file. Check.
My C code can find and execute the static main() function. Check.
My C code can _not_ find the static foo() function. Bewildered.
Here's the line that finds the main() function:
mid = (*env)->GetStaticMethodID(env, cls,"main","([Ljava/lang/String;)V");
and here's the line that does NOT find the static foo() function:
mid = (*env)->GetStaticMethodID(env, cls,"foo","(Ljava/lang/String;)Ljava/lang/String;");
It seems like if main() can be found, then foo() should also be found. The only thing I can think of is that the signature is wrong.
For a function that takes a String[] and returns a void (like main()), the signature is:
"([Ljava/lang/String;)V"
For a function that takes a String and returns a String, it seems like the signature ought to be:
"(Ljava/lang/String;)Ljava/lang/String;"
but this is the first time I've ever used JNI (or the Invocation API), so I'm on really uncertain ground.
Does anyone have any ideas? Thanks!!!
Pete

