NoClassDefFoundError - 无法初始化类......? [英] NoClassDefFoundError - could not initialize class ...?

查看:2507
本文介绍了NoClassDefFoundError - 无法初始化类......?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编写简单测试程序时出错:

I am getting an error while writing my simple test program:

package Xbee;

import com.rapplogic.xbee.api.XBee;
import com.rapplogic.xbee.api.XBeeException;

public class XbeeTest {

    public static void main(String[] args) {
        // TODO Auto-generated method stub

        XBee xbee = new XBee();

        try {
            xbee.open("COM22", 9600);
        } catch (XBeeException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

}

我得到以下内容:

java.lang.UnsatisfiedLinkError: no rxtxSerial in java.library.path thrown while loading gnu.io.RXTXCommDriver
Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class gnu.io.RXTXVersion
    at gnu.io.CommPortIdentifier.<clinit>(CommPortIdentifier.java:123)
    at com.rapplogic.xbee.RxTxSerialComm.openSerialPort(RxTxSerialComm.java:71)
    at com.rapplogic.xbee.RxTxSerialComm.openSerialPort(RxTxSerialComm.java:61)
    at com.rapplogic.xbee.api.XBee.open(XBee.java:140)
    at Xbee.XbeeTest.main(XbeeTest.java:14)

整个问题是它无法初始化类gnu.io.RXTXversion,这是一个rtxtcomm.jar的prt,我已将其包含在我的Maven依赖项中:

The whole problem is that it cannot initialize the class gnu.io.RXTXversion, which is a prt of rtxtcomm.jar, which I have included in my Maven dependency:

<dependency>
    <groupId>org.bidib.jbidib.org.qbang.rxtx</groupId>
    <artifactId>rxtxcomm</artifactId>
    <version>2.2</version>
</dependency>

任何想法?谢谢。

推荐答案

正如我之前在评论中提到的那样,您还需要本地库才能使其正常工作。把它放在$ {JRE_HOME} / lib / i386

As I previously mention in comment, you need also native library to make it work. Put it in ${JRE_HOME}/lib/i386

好文章: http://pharos.ece.utexas.edu/wiki/index.php/How_to_Access_Your_Serial_Port_using_Java

并引用来自文章:


$ wget http://rxtx.qbang.org/pub/rxtx/rxtx-2.1-7-bins-r2.zip

解压缩rxtx存档并安装它。以下命令假定
您的JVM位于/ usr / lib / jvm / java-6-openjdk /中,并且您使用32位x86计算机是
。如果您有不同的JVM或系统架构(即
64位),则需要稍微修改这些
命令。

Unzip the rxtx archive and install it. The following commands assume your JVM is located in /usr/lib/jvm/java-6-openjdk/ and that you are using a 32-bit x86 computer. You will need to slightly modify these commands if you have a different JVM or system architecture (i.e., 64-bit).

$ sudo apt-get install zip

$ sudo apt-get install zip

$ unzip rxtx-2.1-7-bins-r2.zip

$ unzip rxtx-2.1-7-bins-r2.zip

$ cd rxtx-2.1-7-bins-r2

$ cd rxtx-2.1-7-bins-r2

$ sudo cp RXTXcomm.jar / usr / lib / jvm / java-6-openjdk / jre / lib / ext /

$ sudo cp RXTXcomm.jar /usr/lib/jvm/java-6-openjdk/jre/lib/ext/

$ sudo cp Linux / i686-unknown-linux-gnu / librxtx * / usr / lib / jvm / java-6-openjdk / jre / lib / i386 /

$ sudo cp Linux/i686-unknown-linux-gnu/librxtx* /usr/lib/jvm/java-6-openjdk/jre/lib/i386/

这篇关于NoClassDefFoundError - 无法初始化类......?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆