2013-08-07 381 views
7

我正在開發XUbuntu 13.04並開發swing應用程序。因爲我只是想嘗試該應用程序,所以在啓動時遇到了java.lang.NoClassDefFoundError: Could not initialize class java.awt.Toolkitjava.lang.NoClassDefFoundError:無法初始化java.awt.Toolkit類

我發現了關於服務器/客戶端虛擬機的幾個問題,並注意到我有一個服務器虛擬機,而對於Linux 64,沒有客戶端虛擬機了。但恕我直言,這個問題不應該依賴於我在哪個虛擬機上運行。

有沒有人注意到這個問題並解決了它?我究竟做錯了什麼?使用64bit jdk一切正常,但是當我嘗試使用32位jdk時,啓動失敗。

在此先感謝!

PS:Java版本是1.7.0_25,並用相同1.7.0_09

編輯

當使用無頭模式,將發生以下情況除外:

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) 
+1

可以(http://stackoverflow.com/questions/5576986/servlet-giving-error-java-lang-noclassdeffounderror) –

+0

描述這裏]問題我考慮過這個選項,但是'-Djava.awt.headless = true'有一些'HeadlessException's。這個選項是否也適用於擺動應用程序? –

+0

是類似於[描述]的異常(http://stackoverflow.com/questions/5218870/getting-a-headlessexception-no-x11-display-variable-was-set)? –

回答

29

好了,終於我找到了回答。感謝負擔!問題是我安裝了libxtst6,但只安裝了它的64位版本。

sudo apt-get install libxtst6:i386爲我做了詭計。

我是怎麼找到這個答案的?我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 

所以這是一點,當我結束我的信任和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) 
+1

這個固定的問題:在線程 '異常「主要」 java.lang.NoClassDefFoundError:無法初始化類的java .awt.Toolkit' – ngakak

相關問題