• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JNI problem

 
fahad siddiqui
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a AWT frame, on a button press, i need to call C++ code.
So, i wrote a JNI call and called the method of C++ from actionPerformed.
Made the dll, started the java program. I think the dll were found correctly, because, before the program was not starting with a library not found error.
But, now it loads and the AWT frame shows up, on the button click i get this Error:
Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: startCode
at com.MainFrame.startCode(Native Method)
at com.MainFrame.actionPerformed(MainFrame.java:113)
at java.awt.Button.processActionEvent(Unknown Source)
at java.awt.Button.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

This is the code i wrote in java

private native void startCode();

static{
System.loadLibrary("MyArgs");
}

if(textField.getText().trim().length()>0){
//Good
//Get the data and call the c++ area
System.out.println("finally calling "+selectedFileName);
startCode();
}

etc...

Please help me out, i think this problem is coming from some AWT error.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
UnsatisfiedLinkError simply means that a necessary native method wasn't found. If you're not getting an error on the loadLibrary call, then probably your method doesn't have the right signature. You mention C++ -- one common error is forgetting to declare the method 'extern "C"' so that it isn't name-mangled when it's compiled.

We'd need to see the native code to offer any more advice.
 
fahad siddiqui
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is my C++ code

This is my header file generated by javah



Please advise. I am using (build 1.5.0_11-b03) version of java and i am using CodeBlocks to compile the C++ code as a Dynamic Link Library. Also, the compiler being used for c++ by codeblocks is mingw32.
Can you tell me how to compile the C++ code on command-line using mingw32, because when i try to register the dll, regsvr32, it fails. Would i need to compile the c++ through command line?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic