java调用jni的时候老是抛Exception in thread "main" java.lang.UnsatisfiedLinkError为啥呢?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java调用jni的时候老是抛Exception in thread "main" java.lang.UnsatisfiedLinkError为啥呢?相关的知识,希望对你有一定的参考价值。

我的dll文件再里面了啊,怎么提示加载不到呢,求高手帮我解决一下啊,头晕啊?????????????????????????????

参考技术A 源代码发过来追问

谢谢你哦,这个问题我已经解决了,是把 。class文件放到 lib目录中,。dll文件放入bin目录中就可以了

追答

class放到lib中,dll放到bin中,不会吧??
这真是闻所未闻啊。。
正常作法是dll放到项目目录中,就是bin外面
然后在main方法中调用System.loadLibrary("HelloWorld.dll")

java 重新抛出异常

一.有时希望把刚捕获的异常重新抛出,尤其时在使用Exception捕获所以异常的时候,既然已经得到了对当前异常对象的引用,可以重新把它抛出:

catch(Exception e){
      System.out.println("An exception was thrown");
     throw e;
}

二 :

1.重新抛出异常会把异常抛给上一级环境中的异常处理程序,同一个try块的后续catch字句将忽略.

2.异常对象的所有信息都得以保持,所以高一级环境中捕获此异常的处理程序可以从这个异常对象中得到所有消息.

3.如果只是把当前异常对象重新抛出,那么printStackTrace()方法显示的将是原来异常抛出点的调用栈信息,而非重新抛出点的信息.

想要更新这个信息,可以调用fillInStackTrace()方法,这将返回一个Throwable对象,它是通过把当前调用栈信息填入原来那个异常对象而建立的.

package exceptions;
//: exceptions/Rethrowing.java
// Demonstrating fillInStackTrace()

public class Rethrowing {
  public static void f() throws Exception {
    System.out.println("originating the exception in f()");
    throw new Exception("thrown from f()");
  }
  public static void g() throws Exception {
    try {
      f();
    } catch(Exception e) {
      System.out.println("Inside g(),e.printStackTrace()");
      e.printStackTrace(System.out);
      throw e;
    }
  }
  public static void h() throws Exception {
    try {
      f();
    } catch(Exception e) {
      System.out.println("Inside h(),e.printStackTrace()");
      e.printStackTrace(System.out);
      throw (Exception)e.fillInStackTrace();
    }
  }
  public static void main(String[] args) {
    try {
      g();
    } catch(Exception e) {
      System.out.println("main: printStackTrace()");
      e.printStackTrace(System.out);
    }
    try {
      h();
    } catch(Exception e) {
      System.out.println("main: printStackTrace()");
      e.printStackTrace(System.out);
    }
  }
} /* Output:
originating the exception in f()
Inside g(),e.printStackTrace()
java.lang.Exception: thrown from f()
        at Rethrowing.f(Rethrowing.java:7)
        at Rethrowing.g(Rethrowing.java:11)
        at Rethrowing.main(Rethrowing.java:29)
main: printStackTrace()
java.lang.Exception: thrown from f()
        at Rethrowing.f(Rethrowing.java:7)
        at Rethrowing.g(Rethrowing.java:11)
        at Rethrowing.main(Rethrowing.java:29)
originating the exception in f()
Inside h(),e.printStackTrace()
java.lang.Exception: thrown from f()
        at Rethrowing.f(Rethrowing.java:7)
        at Rethrowing.h(Rethrowing.java:20)
        at Rethrowing.main(Rethrowing.java:35)
main: printStackTrace()
java.lang.Exception: thrown from f()
        at Rethrowing.h(Rethrowing.java:24)
        at Rethrowing.main(Rethrowing.java:35)
*///:~

三. 有可能在捕获异常后抛出了另一种异常,这么做的话,得到的效果类似于使用fillInStackTrace(),有关原来异常发生点的信息会丢失,剩下的是与新的抛出点有关的信息:

//最后的那个异常仅知道自己来自main(),而对f()一无所知
package
exceptions; //: exceptions/RethrowNew.java // Rethrow a different object from the one that was caught. class OneException extends Exception { public OneException(String s) { super(s); } } class TwoException extends Exception { public TwoException(String s) { super(s); } } public class RethrowNew { public static void f() throws OneException { System.out.println("originating the exception in f()"); throw new OneException("thrown from f()"); } public static void main(String[] args) { try { try { f(); } catch(OneException e) { System.out.println( "Caught in inner try, e.printStackTrace()"); e.printStackTrace(System.out); throw new TwoException("from inner try"); } } catch(TwoException e) { System.out.println( "Caught in outer try, e.printStackTrace()"); e.printStackTrace(System.out); } } } /* Output: originating the exception in f() Caught in inner try, e.printStackTrace() OneException: thrown from f() at RethrowNew.f(RethrowNew.java:15) at RethrowNew.main(RethrowNew.java:20) Caught in outer try, e.printStackTrace() TwoException: from inner try at RethrowNew.main(RethrowNew.java:25) *///:~

 


以上是关于java调用jni的时候老是抛Exception in thread "main" java.lang.UnsatisfiedLinkError为啥呢?的主要内容,如果未能解决你的问题,请参考以下文章

JNI中使用mingw 生成dll。但java调用中出现错误 Exception in thread "main" java.lang.UnsatisfiedLinkEr

手机QQ读取消息的时候老是显示null pointer exception,这是怎么回事,该怎么办?

java 带有exception的父类方法覆盖问题

带有 JNI 的 C++ 应用程序抛出错误“找不到 jvm.dll。重新安装应用程序可以修复....”

错误: 代理抛出异常错误: java.rmi.server.ExportException: Port already in use: 1099; nested exception is: java.

JNI在应用程序中检测到错误:JNI FindClass调用挂起异常java.lang.NoSuchMethodError:没有非静态方法“Lchirpconnect / SDK