Hi
I am trying to call a c++ function from java. I used the javah -jni option to generate the header file. Then I defined the function in a c++ file as follows.
JNIEXPORT jstring JNICALL Java_TestNative_GetMilliSecTime
(JNIEnv *env, jobject jobj){
struct _timeb timebuffer;
char *timeline;
//CString tempTime;
char OutputTime[200];
_ftime( &timebuffer );
timeline = ctime( & ( timebuffer.time ) );
sprintf( OutputTime, "%.19s.%hu %s", timeline, timebuffer.millitm, &timeline[20] );
return (newJavaString(env, OutputTime));
}
The java file is given below:
public class TestNative
{
public native String GetMilliSecTime();
static {
System.loadLibrary("GetTime");
}
public static void main(String args[]){
TestNative nt = new TestNative();
System.out.println(nt.GetMilliSecTime());
}
}
The code compiles, but when I run it I get the following error:
Exception in thread "main" java.lang.UnsatisfiedLinkError: GetMilliSecTime
at TestNative.main(TestNative.java:10)
Any suggestions???
Thanks in advance
Shiva
-
Calling a native function from java (2 messages)
- Posted by: Shiva Ramadoss
- Posted on: February 23 2001 17:19 EST
Threaded Messages (2)
- Calling a native function from java by Ian Young on May 30 2001 12:12 EDT
- Calling a nativ.. fnct from java by gauravdeep sagar on June 02 2004 05:37 EDT
-
Calling a native function from java[ Go to top ]
- Posted by: Ian Young
- Posted on: May 30 2001 12:12 EDT
- in response to Shiva Ramadoss
Hi,
I have the same problem and would be interested to know if you found a solution to this.
Thanks
Ian -
Calling a nativ.. fnct from java[ Go to top ]
- Posted by: gauravdeep sagar
- Posted on: June 02 2004 05:37 EDT
- in response to Shiva Ramadoss
This error might come because your dll file formed from the CPP file might not be in the same directory as the final JAVA file. just check that again. if not you neet to copy that file ...and also include the same exception error in your code. Hope that works out.