如何解决“找不到'jnu'的类文件。”

时间:2019-04-23 10:27:21

标签: java java-native-interface

我正在使用Java本机接口进行数学计算,但是当我尝试在终端上执行它时,会显示以下错误。

kiran @ kiran-X510UNR:〜$ javac jnu.java

kiran @ kiran-X510UNR:〜$ javah -jni jnu

错误:找不到'jnu'的类文件。

public native int add(int n1,int n2);
public native int sub(int n1,int n2);
public native int mul(int n1,int n2);
public native int div(int n1,int n2);

public static void main(String a[])
{
    jnu tj = new jnu();

    int ch,n1,n2;
    Scanner sh = new Scanner(System.in);

    System.out.println("Enter two numbers ");
    n1 = sh.nextInt();
    n2 = sh.nextInt();      

    System.out.println("\n1.Add\n2.Sub\n3.Mul\n4.Div");
    ch = sh.nextInt();

    switch(ch)
    {
        case 1:
            System.out.println("Addition is : "+tj.add(n1,n2));break;
        case 2:
            System.out.println("Subtraction is : "+tj.sub(n1,n2));break;
        case 3:
            System.out.println("Multiplication is : "+tj.mul(n1,n2));break;
        case 4:
            System.out.println("Division is : "+tj.div(n1,n2));break;
        default:
            System.out.println("Wrong choice");break;
    }       
}

static
{
    System.loadLibrary("jnu");
}

test.c

...

JNIEXPORT jint JNICALL Java_jnu_add(JNIEnv *env,jobject object,jint n1,jint n2)
{
    return n1+n2;
}

JNIEXPORT jint JNICALL Java_jnu_sub(JNIEnv *env,jobject object,jint n1,jint n2)
{
    return n1-n2;
}

JNIEXPORT jint JNICALL Java_jnu_mul(JNIEnv *env,jobject object,jint n1,jint n2)
{
    return n1*n2;
}

JNIEXPORT jint JNICALL Java_jnu_div(JNIEnv *env,jobject object,jint n1,jint n2)    
{    
    return n1/n2;        
}

...

我希望应该生成头文件,但错误显示找不到jnu的类。

0 个答案:

没有答案