class HelloWorld {
public native void print(); //native method
static //static initializer code
{
try{
String path = System.getProperty("java.library.path");
System.out.println(path);
System.loadLibrary("CLibHelloWorld1");
//System.load("C:/TE_CDA_Project/Test/native/CLibHelloWorld1.dll");
//Runtime.getRuntime().load("C:/TE_CDA_Project/Test/native/CLibHelloWorld1.dll");
System.out.println("Loaded CallApi");
}catch(UnsatisfiedLinkError e){
e.printStackTrace();
}
}
public static void main(String[] args)
{
HelloWorld hw = new HelloWorld();
hw.print();
}
}java.lang.UnsatisfiedLinkError中使用JNI
輸出:
C:\TE_CDA_Project\Test\native
Loaded CallApi
Exception in thread "main" java.lang.UnsatisfiedLinkError: Graph.HelloWorld.print()V
at Graph.HelloWorld.print(Native Method)
at Graph.HelloWorld.main(HelloWorld.java:26)
這是最有可能,因爲的java.library.path路徑變量目前尚未設置。這是Java提取所需庫的路徑。 – 2013-05-14 09:53:07
@Paritosh:我想你應該也發佈你的本地代碼。由於本地方法的簽名錯誤,通常會發生此異常。看到這裏的例子:http://stackoverflow.com/questions/16518490/java-lang-unsatisfiedlinkerror-jni/16519301#16519301(如果你面臨同樣的問題,不要忘記+1這個答案) – Zax 2013-05-15 04:25:30