我早些时候在这里问了一个问题:NoClassDefFoundError with bluecove's javax.microedition 但没有得到回应。
我正在尝试运行一些需要蓝牙的 java 代码 (Server.java),所以我在 C:\Program Files\Java 中安装了 bluecove-2.1.0.jar 文件。
我用 javac -cp "C:\Program Files\Java\bluecove-2.1.0.jar"; 编译我的代码。 Server.java
并使用 java Server -cp "C:\Program Files\Java\bluecove-2.1.0.jar"
编译成功,但是运行时报错:
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: javax/microedition/io/Connection
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.privateGetMethodRecursive(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: javax.microedition.io.Connection
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 7 more
我哪里出错了?
编辑:根据 Minus 的回答,为了修复随后出现的错误,我还需要使用从 http://snapshot.bluecove.org/distribution/download/2.1.1-SNAPSHOT/2.1.1-SNAPSHOT.63/ 下载的不同 .jar 文件。
最佳答案
问题是 .dll 没有正确加载。
该库应该包含一个.dll,将保存在磁盘上并加载,程序可能无法将.dll 保存到磁盘或无法读取它。
提取.dll 并按照bluecove installation instructions 操作在本地库位置。
例如:
创建一个目录c:\blue
,和一个目录blue\lib
。
像这样放置文件:
C:\blue\Sever.java
C:\blue\Sever.class
C:\blue\[bluecove_native_library].dll
C:\blue\lib\bluecove-2.1.0.jar
在 c:\blue 上打开一个 cmd(命令提示符)
尝试像这样运行应用程序:
java -cp .;lib\bluecove-2.1.0.jar -Dbluecove.native.resource=false Server
这样您将在类路径中同时拥有 Server.class 和 bluecove-2.1.0.jar 以及路径中的 DLL(因为在 Windows 上,当前目录在路径中)。
关于java - NoClassDefFoundError 在java中使用蓝牙,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42297711/