aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes JNI problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "JNI problem" Watch "JNI problem" New topic
Author

JNI problem

fahad siddiqui
Ranch Hand

Joined: Jun 14, 2006
Posts: 85
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

Joined: Jul 08, 2003
Posts: 24187
    
  34

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.


[Jess in Action][AskingGoodQuestions]
fahad siddiqui
Ranch Hand

Joined: Jun 14, 2006
Posts: 85
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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JNI problem