Skip to Main Content

Java HotSpot Virtual Machine

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

java.lang.UnsatisfiedLinkError:

843829Sep 21 2008 — edited Sep 21 2008
Hi everyone, i am trying to learn jni,i got these codes on the web and am i trying them out. now i have a problem.

first here are the codes:
jniexample.java
import java.io.*;
import java.util.*;

class jniexample {                                                              
   static {
        try {
            System.loadLibrary( "jniexample" );
	      } 
	     catch( UnsatisfiedLinkError e ) {
	        System.out.println( "Could not load native code." ); 
	      System.exit(1);
	    }
   }

   public static void main( String [] args ) throws IOException {               
        
      String strUser;
      String strPass;
      BufferedReader console = new BufferedReader( new InputStreamReader( System.in ) ); 
         
         strUser = console.readLine();                                                            
         strPass = console.readLine(); 
 
	 validUser( strUser, strPass );                                  
   }                                                                            
                            
   public static native boolean validUser( String strUser, String strPass );    
}  
jniexample.cpp
JNIEXPORT jboolean JNICALL Java_jniexample_validUser
  ( JNIEnv *env, jobject obj, jstring user, jstring pass )
{
  struct spwd   *pw;
  char          salt[2];
  char          *cpass;
  jboolean      retVal= JNI_FALSE;
  
  const char *pUser = env->GetStringUTFChars( user, 0 );
  const char *pPass = env->GetStringUTFChars(pass, 0 );
  
  printf("Hello %s, you are wellcome with password %s\n",pUser,pPass);
 
                                                   
   env->ReleaseStringUTFChars(pass, pUser );
  env->ReleaseStringUTFChars(pass, pPass );                           
retVal = JNI_TRUE; 
  return retVal;                                                               
}
my steps:

javac jniexample.java
javah -jni jniexample
g++ -shared -o libjniexample.so jniexample.cpp -lstdc++ -I/usr/lib/jvm/java-6-sun/include -I/usr/lib/jvm/java-6-sun/include/linux

now when i run the program i get the error:

Exception in thread "main" java.lang.UnsatisfiedLinkError: jniexample.validUser(Ljava/lang/String;Ljava/lang/String;)Z
at jniexample.validUser(Native Method)
at jniexample.main(jniexample.java:24)


also i have done:

export LD_LIBRARY_PATH=(CURRENT DIRECTORY WHERE THE libjniexample.so IS LOCATED)

please give me suggestions ,,,thanks in advance

Edited by: prakash0104 on Sep 21, 2008 2:33 AM

Edited by: prakash0104 on Sep 21, 2008 2:40 AM

Edited by: prakash0104 on Sep 21, 2008 2:44 AM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 19 2008
Added on Sep 21 2008
7 comments
489 views