I'm really new to java programming therefore I apologize in advance if this sounds like a stupid question.
I'm using JNI to invoke C code by creating a Swing JFrame and displays it. The code is fairly simple, and the Java-code is working fine if I set frame visibility to false (i.e. the "hello" method is called) whereas when I set frame visibility to true, nothing happens(i.e. the "hello" method is not called).
I'm using JNI to invoke C code by creating a Swing JFrame and displays it. The code is fairly simple, and the Java-code is working fine if I set frame visibility to false (i.e. the "hello" method is called) whereas when I set frame visibility to true, nothing happens(i.e. the "hello" method is not called).
Code:
Test.java
public class Test extends JFrame {
private JPanel contentPane;
public static Container root;
/**
* Launch the application.
*/
public static void main(String[] args) {
try {
Test frame = new Test();
new JNIServer().hello("world"); // where hello is native method
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
}
JNIServer.java
public class JNIServer{
public native void hello(String name);
static {
System.out.println("Inload library");
System.loadLibrary("JNI_Lib");
}
}
JNIServer.c
#include <stdio.h>
#include "JNIServer.h"
JNIEXPORT void JNICALL Java_JNIServer_hello
(JNIEnv *env, jobject jthis, jstring sims)
{
printf(" C: In hello ");
}