Just getting started with JNI, and not sure why the log messages in C don't post to the terminal until after the app terminates.
public static native long initialize(String arg);
public static native boolean hasImage();
public static native void dispose();
public static void main(String[] args) {
long id = ClipboardHelper.initialize("");
System.out.println(id);
try {
System.in.read(); //wait for enter key
} catch (IOException e) {
}
ClipboardHelper.dispose();
}
C code:
JNIEXPORT jlong JNICALL Java_com_mypackage_ClipboardHelper_initialize
(JNIEnv *env, jclass obj, jstring arg) {
printf("hello world");
return 1;
}
When I run the app, I see it print 1 from the Java println
method call:
1
But it doesn't print hello world
until I hit the enter key to continue the app.
1
hello world
I can see that the C function returned, because the correct number was printed in Java. In fact, I can call several native methods and only after I press enter do all the queued up printf
message appear.