Java Reference
In-Depth Information
myEnv , myClass , "main" , "([Ljava/lang/String;)V" );
/* myMethod = (*myEnv)->GetMethodID(myEnv, myClass, "test", "(I)I"); */
iif ( myMethod == NULL ) {
fprintf ( stderr , "GetStaticMethodID failed\\n" );
exit ( 1 );
}
/* Since we're calling main, must pass along the command line arguments,
* in the form of Java String array
*/
iif (( stringClass = ( * myEnv ) -> FindClass ( myEnv , "java/lang/String" )) == NULL ){
fprintf ( stderr , "get of String class failed!!\\n" );
exit ( 1 );
}
/* make an array of Strings, subtracting 1 for progname & 1 for the
* java class name */
iif (( args = ( * myEnv ) -> NewObjectArray ( myEnv , argc - 2 , stringClass , NULL )) == NULL ) {
fprintf ( stderr , "Create array failed!\\n" );
exit ( 1 );
}
/* fill the array */
for
for ( i = 2 ; i < argc ; i ++ )
( * myEnv ) -> SetObjectArrayElement ( myEnv ,
args , i - 2 , ( * myEnv ) -> NewStringUTF ( myEnv , argv [ i ]));
/* finally, call the method. */
( * myEnv ) -> CallStaticVoidMethodA ( myEnv , myClass , myMethod , & args );
/* And check for exceptions */
iif (( tossed = ( * myEnv ) -> ExceptionOccurred ( myEnv )) != NULL ) {
fprintf ( stderr , "%s: Exception detected:\\n" , argv [ 0 ]);
( * myEnv ) -> ExceptionDescribe ( myEnv );
/* writes on stderr */
( * myEnv ) -> ExceptionClear ( myEnv );
/* OK, we're done with it. */
}
( * jvm ) -> DestroyJavaVM ( jvm );
/* no error checking as we're done anyhow */
return
return 0 ;
}
[ 65 ] kwrite is Unix-specific; it's a part of the K Desktop Environment (KDE) .
 
Search WWH ::




Custom Search