一个非常简单的问题。我尝试运行一个非常简单的演示来创建和显示Eclipse中的Window Frame,但没有发生任何事情。没有错误,没有窗口,代码运行到完成。
我添加了断点,并确保代码按预期运行。代码直接来自Java教程(FrameDemo),我只是将包重命名为适合我放置的位置(该包中的其他代码运行良好):
package ui;
import java.awt.*;
import javax.swing.*;
/* FrameDemo.java requires no other files. */
public class FrameDemo {
/**
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event-dispatching thread.
*/
private static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("FrameDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel emptyLabel = new JLabel("");
emptyLabel.setPreferredSize(new Dimension(175, 100));
frame.getContentPane().add(emptyLabel, BorderLayout.CENTER);
//Display the window.
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
我的设置(开普勒SR2):
- eclipse.buildId=4.3.2.M20140221-1700
- java.版本=1.8.0_05
- java.vendor=Oracle公司
- BootLoader常量:OS=macosx,ARCH=x86_64,WS=可可,NL=en_US
- 框架参数:-product org.eclipse.ep.package.java.product-keyring/Users/steve/.eclipse_keyring-showlocation
- 命令行参数:-os macosx-ws cocoa-arch x86_64-product org.eclipse.epp.package.java.product-keyring/Users/steve/.eclipse_keyring-showlocation
我还查看了配置->错误日志;仍然没有任何错误。我尝试了其他类似的演示,结果相同。
任何帮助都将不胜感激,因为我已经被困在这上面一天多了。
原来我有一个库问题。我已经从jfreechart导入了.lib目录中的所有jar。事实上,只需要两个,一些不必要的被标记为swt和实验性的。一旦我移除了所有不需要的,进行了清洁和重建,一切都很好。
奇怪的是,将jfreechart库(包括冲突的jar)的顺序更改为底部并没有帮助,额外的jar不得不被移除。
不是jfreechart的问题,显然是我自己的库导入问题。如果遇到这种情况,我建议您尝试删除一些可能冲突的库,然后清理、构建并再次运行。
感谢"满是鳗鱼的气垫船"和其他帮助我的人。
macOS+Eclipse+swt.jar给出了这个问题。
事实证明,在macOS中,如果类路径中有swt.jar,Eclipse在启动GUI应用程序时会添加一个特殊的参数-XstartOnFirstThread
。从外部库(用于构建类路径)中删除swt.jar之后,问题解决了。