java JNI程序在eclipse运行的时候出现一个问题,求大牛来解决下啊
java 项目中使用jni编程在生成头文件和生成库文件都已经成功了,但是运行main函数的时候报错:could not find the main class:com.fjnu.InstanceFieldAccess. Program will exit.错误;没有用java jni的时候单独运行java程序是可以正常运行的的请大神们帮忙看看什么原因,下面是java文件的代码:
package com.fjnu;
public class InstanceFieldAccess {
private String s;
private native void accessField();
public static void main(String args[]) {
InstanceFieldAccess c = new InstanceFieldAccess();
c.s = "abc";
c.accessField();
System.out.println("In Java:");
System.out.println(" c.s = "" + c.s + """);
}
static {
System.loadLibrary("InstanceFieldAccess");
}
}
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class com_fjnu_InstanceFieldAccess */
#ifndef _Included_com_fjnu_InstanceFieldAccess
#define _Included_com_fjnu_InstanceFieldAccess
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: com_fjnu_InstanceFieldAccess
* Method: accessField
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_com_fjnu_InstanceFieldAccess_accessField
(JNIEnv *, jobject);
#ifdef __cplusplus
}
#endif
#endif
#include <com_fjnu_InstanceFieldAccess.h>
#include<stdio.h>
#include <jni.h>
#include <string.h>
JNIEXPORT void JNICALL Java_com_fjnu_InstanceFieldAccess_accessField
(JNIEnv *env , jobject obj)
{
jfieldID fid; /* store the field ID */
jstring jstr;
const char *str;
/* Get a reference to obj's class */
jclass cls = (*env)->GetObjectClass(env, obj);
printf("In C:\n");
/* Look for the instance field s in cls */
fid = (*env)->GetFieldID(env, cls, "s","Ljava/lang/String;");
if (fid == NULL) {
return; /* failed to find the field */
}
/* Read the instance field s */
jstr = (*env)->GetObjectField(env, obj, fid);
str = (*env)->GetStringUTFChars(env, jstr, NULL);
if (str == NULL) {
return; /* out of memory */
}
printf(" c.s = "%s"\n", str);
(*env)->ReleaseStringUTFChars(env, jstr, str);
/* Create a new string and overwrite the instance field */
jstr = (*env)->NewStringUTF(env, "123");
if (jstr == NULL) {
return; /* out of memory */
}
(*env)->SetObjectField(env, obj, fid, jstr);
}