Skip to Main Content

Java APIs

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!

FindClass() throws java.lang.UnsatisfiedLinkError exception

843810Aug 23 2005 — edited Aug 23 2005
Hi All,

I am using a JNI to make my C program to communicate with the GUI developed in Java Swings. In my C program I have used FindClass() method to find the java class. While exececuting my C program, I got the following exception,


Exception in thread "main" java.lang.UnsatisfiedLinkError: /usr/java/jre1.5.0_04/lib/i386/libawt.so: /usr/java/j2sdk1.4.2_08/jre/lib/i386/libmlib_image.so: version `VER_1.1' not found (required by /usr/java/jre1.5.0_04/lib/i386/libawt.so)
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(Unknown Source)
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at sun.security.action.LoadLibraryAction.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.awt.NativeLibLoader.loadLibraries(Unknown Source)
at sun.awt.DebugHelper.<clinit>(Unknown Source)
at java.awt.Component.<clinit>(Unknown Source)

I have ensured that the libawt.so and ibmlib_image.so paths are set in LD_LIBRARY_PATH. Inspite of that I am not able to access the java class because of the above mentioned exception. Please help me out in this.

For your reference, I am attaching the code with this,

#include <jni.h>
 
int main() 
{
	JavaVMOption options[2]; 
	JNIEnv *env;
	JavaVM *jvm; 
	JavaVMInitArgs vm_args;
	long status;
	jclass cls;
	jobject obj;
	jmethodID mid;
	jstring jstr;
	char str[25];
       options[0].optionString =        "-Djava.class.path=/home/maniyan/work/Dhruv_proj/vers/v5"; 
	options[1].optionString = "-verbose:jni";
	memset(&vm_args, 0, sizeof(vm_args));
        vm_args.version = JNI_VERSION_1_4;
	vm_args.nOptions = 1;
	vm_args.options = options;
	vm_args.ignoreUnrecognized = 1;
	status = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
	printf("status %d\n",status);
	if (status != JNI_ERR)
	{
		printf("Exception %d\n",(*env)->ExceptionCheck(env));
		cls = (*env)->FindClass(env, "frame_main_v1");
		printf("Exception %d\n",(*env)->ExceptionCheck(env));
		if ((*env)->ExceptionCheck(env)) {
		(*env)->ExceptionDescribe(env);
		(*env)->ExceptionClear(env);
	}
	if(cls !=0) 
	{
	        //printf("am here\n");
		mid = (*env)->GetStaticMethodID(env, cls, "display_message", "(Ljava/lang/String;)V"); 
		printf("Method %d\n",mid);
		if(mid !=0)
		{	 strcpy(str,"Hello world");
			 (*env)->CallStaticCharMethod(env, cls, mid, (*env)->NewStringUTF(env, str)); 
		}
	}
	(*jvm)->DestroyJavaVM(jvm);
	return 0;
    }
 else {
		printf("some error\n");
		return -1;
	}
}
 
Thanks in adv,
Cool Dude
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 20 2005
Added on Aug 23 2005
1 comment
203 views