我是一個Eclipse新手,我試圖構建一個混合的AWT/SWT應用程序。這裏是我的代碼:混合AWT和SWT時Java UnsatisfiedLinkError?
public class HelloWorldSWT {
public static void main(String[] args) {
Frame frame = new Frame("My AWT Frame"); // java.awt.Frame
frame.setLayout(new BorderLayout());
Canvas canvas = new Canvas(); // java.awt.Canvas
frame.add(canvas, BorderLayout.CENTER);
frame.setVisible(true);
Display display = new Display(); // display object to manage SWT lifecycle.
Shell swtShell = SWT_AWT.new_Shell(display, canvas);
Button m_button = new Button(swtShell, SWT.PUSH);
m_button.setText("button");
// invoke the AWT frame rendering by making the frame visible
// This starts the EDT
frame.setVisible(true);
// standard SWT dispatch loop
while(!swtShell.isDisposed())
{
if(!display.readAndDispatch())
display.sleep();
}
swtShell.dispose();
}
}
編譯沒有問題,但是當我在Eclipse中運行它的應用程序,我得到以下錯誤:
Exception in thread "main" java.lang.UnsatisfiedLinkError: sun.awt.SunToolkit.getAppContext(Ljava/lang/Object;)Lsun/awt/AppContext; at sun.awt.SunToolkit.getAppContext(Native Method) at sun.awt.SunToolkit.targetToAppContext(Unknown Source) at sun.awt.windows.WComponentPeer.postEvent(Unknown Source) at sun.awt.windows.WComponentPeer.postPaintIfNecessary(Unknown Source) at sun.awt.windows.WComponentPeer.handlePaint(Unknown Source) at sun.java2d.d3d.D3DScreenUpdateManager.repaintPeerTarget(Unknown Source) at sun.java2d.d3d.D3DScreenUpdateManager.createScreenSurface(Unknown Source) at sun.awt.windows.WComponentPeer.replaceSurfaceData(Unknown Source) at sun.awt.windows.WComponentPeer.replaceSurfaceData(Unknown Source) at sun.awt.windows.WComponentPeer.setBounds(Unknown Source) at sun.awt.windows.WWindowPeer.setBounds(Unknown Source) at sun.awt.windows.WComponentPeer.initialize(Unknown Source) at sun.awt.windows.WCanvasPeer.initialize(Unknown Source) at sun.awt.windows.WPanelPeer.initialize(Unknown Source) at sun.awt.windows.WWindowPeer.initialize(Unknown Source) at sun.awt.windows.WFramePeer.initialize(Unknown Source) at sun.awt.windows.WComponentPeer.(Unknown Source) at sun.awt.windows.WCanvasPeer.(Unknown Source) at sun.awt.windows.WPanelPeer.(Unknown Source) at sun.awt.windows.WWindowPeer.(Unknown Source) at sun.awt.windows.WFramePeer.(Unknown Source) at sun.awt.windows.WToolkit.createFrame(Unknown Source) at java.awt.Frame.addNotify(Unknown Source) at java.awt.Window.show(Unknown Source) at java.awt.Component.show(Unknown Source) at java.awt.Component.setVisible(Unknown Source) at java.awt.Window.setVisible(Unknown Source) at HelloWorldSWT.main(HelloWorldSWT.java:20)
我在做什麼錯?
謝謝,我會試試看。 – 2009-08-08 18:14:07
原來我引用了錯誤的SWT jar文件。謝謝你的幫助。 – 2009-08-23 17:53:08