接上一个问题 [https://ask.csdn.net/questions/8071363](Could not find or load main class)
package com.example;
public class FastjsonJNI {
public FastjsonJNI() {
super();
}
private native int add(int a, int b);
static {
System.loadLibrary("fastjson_jni");
//libfastjson_jni
};
public static void main(String args[]){
int ret = 0;
FastjsonJNI fastjsonJNI = new FastjsonJNI();
ret = fastjsonJNI.add(23, 44);
System.out.println("hello world! " + ret + "\n");
}
}
//编译:
javah -jni com.example.FastjsonJNI //生成 .h 头文件
javac -d build/ com/example/FastjsonJNI.java //生成.class文件
//运行出错:
Exception in thread "main" java.lang.UnsatisfiedLinkError: com.example.FastjsonJNI.add(II)I
at com.example.FastjsonJNI.add(Native Method)
at com.example.FastjsonJNI.main(FastjsonJNI.java:23)
:
ret = fastjsonJNI.add(23, 44);