Linux java.lang.NoClassDefFoundError:无法初始化类 java.awt.Toolkit

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18099614/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-07 00:29:15  来源:igfitidea点击:

java.lang.NoClassDefFoundError: Could not initialize class java.awt.Toolkit

javalinuxswing32bit-64bitxubuntu

提问by Bertram Nudelbach

I'm working on XUbuntu 13.04 and developing swing applications. As I just wanted to try that application I ran into java.lang.NoClassDefFoundError: Could not initialize class java.awt.Toolkiton startup.

我正在使用 XUbuntu 13.04 并开发 Swing 应用程序。因为我只是想尝试那个应用程序,所以我java.lang.NoClassDefFoundError: Could not initialize class java.awt.Toolkit在启动时遇到了。

I've found several questions about server/client vms and noticed that I have a server VM and that for Linux 64 there is no client VM anymore. But nevertheless IMHO this problem shouldn't depend on which VM I'm running on.

我发现了几个关于服务器/客户端虚拟机的问题,并注意到我有一个服务器虚拟机,而对于 Linux 64,不再有客户端虚拟机。但是恕我直言,这个问题不应该取决于我正在运行的 VM。

Has anybody else noticed that problem and has solved it? What am I doing wrong? With 64bit jdk everything works fine, but when I try to use the 32bit jdk the startup fails.

有没有其他人注意到这个问题并解决了它?我究竟做错了什么?使用 64 位 jdk 一切正常,但是当我尝试使用 32 位 jdk 时,启动失败。

Thanks in advance!

提前致谢!

P.S.: Java version is 1.7.0_25and same with 1.7.0_09

PS:Java 版本1.7.0_251.7.0_09

EDIT

编辑

When using headless mode, the following exceptions occur:

使用 headless 模式时,会出现以下异常:

java.lang.reflect.InvocationTargetException
    at java.awt.EventQueue.invokeAndWait(EventQueue.java:1272)
    at java.awt.EventQueue.invokeAndWait(EventQueue.java:1247)
    at javax.swing.SwingUtilities.invokeAndWait(SwingUtilities.java:1349)
    at Main.main(Main.java:218)
Caused by: java.awt.HeadlessException
    at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:207)
    at java.awt.Window.<init>(Window.java:535)
    at java.awt.Frame.<init>(Frame.java:420)
    at java.awt.Frame.<init>(Frame.java:385)
    at javax.swing.JFrame.<init>(JFrame.java:180)
    at ..MyFrame.<init>(MyFrame.java:23)

采纳答案by Bertram Nudelbach

Okay, finally I've found the answer. Thanks for the effort! The problem is that I had libxtst6installed but only the 64bit-version of it.

好吧,我终于找到了答案。感谢您的努力!问题是我已经libxtst6安装了它的 64 位版本。

sudo apt-get install libxtst6:i386did the trick for me.

sudo apt-get install libxtst6:i386帮我解决了这个问题。

How did I find this answer? I ldded around a bit, but nothing, as you can see in the following:

我是如何找到这个答案的?我转ldd了一下,但没有,你可以在下面看到:

$ ldd jdk1.7.0_25_x86/jre/lib/i386/xawt/libmawt.so
    linux-gate.so.1 =>  (0xf7769000)
    libpthread.so.0 => /lib/i386-linux-gnu/libpthread.so.0 (0xf76ee000)
    libm.so.6 => /lib/i386-linux-gnu/libm.so.6 (0xf76c2000)
    libawt.so => jdk1.7.0_25_x86/jre/lib/i386/xawt/../libawt.so (0xf760f000)
    libXext.so.6 => /usr/lib/i386-linux-gnu/libXext.so.6 (0xf75fd000)
    libX11.so.6 => /usr/lib/i386-linux-gnu/libX11.so.6 (0xf74c9000)
    libXrender.so.1 => /usr/lib/i386-linux-gnu/libXrender.so.1 (0xf74bf000)
    libdl.so.2 => /lib/i386-linux-gnu/libdl.so.2 (0xf74ba000)
    libXtst.so.6 => /usr/lib/i386-linux-gnu/libXtst.so.6 (0xf74b2000)
    libXi.so.6 => /usr/lib/i386-linux-gnu/libXi.so.6 (0xf74a2000)
    libjava.so => jdk1.7.0_25_x86/jre/lib/i386/xawt../libjava.so (0xf747e000)
    libjvm.so => not found
    libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xf72d5000)
    /lib/ld-linux.so.2 (0xf776a000)
    libjvm.so => not found
    libxcb.so.1 => /usr/lib/i386-linux-gnu/libxcb.so.1 (0xf72b3000)
    libjvm.so => not found
    libverify.so => java/jdk1.7.0_25_x86/jre/lib/i386/xawt/../libverify.so (0xf72a7000)
    libXau.so.6 => /usr/lib/i386-linux-gnu/libXau.so.6 (0xf72a2000)
    libXdmcp.so.6 => /usr/lib/i386-linux-gnu/libXdmcp.so.6 (0xf729b000)
    libjvm.so => not found

So that was the point when I ended trusting my IDE and started a sample application on the command line. And the command line again was nice to me:

所以这就是我结束信任我的 IDE 并在命令行上启动一个示例应用程序的时候。命令行再次对我很好:

$ jdk1.7.0_25_x86/bin/java Main
Exception in thread "main" java.lang.UnsatisfiedLinkError: jdk1.7.0_25_x86/jre/lib/i386/xawt/libmawt.so: libXtst.so.6: cannot open shared object file: No such file or directory
    at java.lang.ClassLoader$NativeLibrary.load(Native Method)
    at java.lang.ClassLoader.loadLibrary1(ClassLoader.java:1957)
    at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1882)
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1843)
    at java.lang.Runtime.load0(Runtime.java:795)
    at java.lang.System.load(System.java:1061)
    at java.lang.ClassLoader$NativeLibrary.load(Native Method)
    at java.lang.ClassLoader.loadLibrary1(ClassLoader.java:1957)
    at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1882)
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1864)
    at java.lang.Runtime.loadLibrary0(Runtime.java:849)
    at java.lang.System.loadLibrary(System.java:1087)
    at sun.security.action.LoadLibraryAction.run(LoadLibraryAction.java:67)
    at sun.security.action.LoadLibraryAction.run(LoadLibraryAction.java:47)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.awt.Toolkit.loadLibraries(Toolkit.java:1646)
    at java.awt.Toolkit.<clinit>(Toolkit.java:1668)
    at java.awt.Component.<clinit>(Component.java:595)
    at Main.main(Main.java:5)