我尝试使用intellij运行netbeans IDE创建的JFrameForm,我从netbeans复制源代码并将其粘贴到新的java类中,并在主函数中创建对象并设置jframe包含的类的可见性并运行它,它给出了以下错误2019-09-21 17:36:31.363Exception in thread "main" java.awt.HeadlessExceptionat java.desktop/java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:208)INFO at java.desktop/java.awt.Window.<init>(Window.java:548)4744 at java.desktop/java.awt.Frame.<init>(Frame.java:423)--- at java.desktop/java.awt.Frame.<init>(Frame.java:388)[ Thread-1] at java.desktop/javax.swing.JFrame.<init>(JFrame.java:180)j.LocalContainerEntityManagerFactoryBean at com.sunTravel.frontend.uiComponents.MainFrame.<init> (MainFrame.java:19): at com.sunTravel.frontend.FrontendApplication.main(FrontendApplication.java:12)Closing JPA EntityManagerFactory for persistence unit 'default'2019-09-21 17:36:31.364 INFO 4744 --- [ Thread-1] .SchemaDropperImpl$DelayedDropActionImpl : HHH000477: Starting delayed evictData of schema as part of SessionFactory shut-down'2019-09-21 17:36:31.367 INFO 4744 --- [ Thread-1] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...2019-09-21 17:36:31.370 INFO 4744 --- [ Thread-1] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.Process finished with exit code 1我的源代码如下,如何解决这个问题?@SpringBootApplicationpublic class FrontendApplication { public static void main(String[] args) { SpringApplication.run(FrontendApplication.class, args); MainFrame mf = new MainFrame(); mf.setVisible(true); }}
2 回答
一只萌萌小番薯
TA贡献1795条经验 获得超7个赞
尝试禁用无头属性,如下所示。 您必须在创建/显示 JFrame 之前执行此操作。
System.setProperty("java.awt.headless", "false"); //Disables headless
一个例子:
SpringApplication.run(MyClass.class, args);
System.setProperty("java.awt.headless", "false");
SwingUtilities.invokeLater(() -> {
JFrame f = new JFrame("myframe");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
});
慕容708150
TA贡献1831条经验 获得超4个赞
尝试这个
public static void main(String[] args) {
SpringApplicationBuilder builder = new SpringApplicationBuilder(DemoApplication.class);
builder.headless(false);
builder.run(args);
MainFrame mf = new MainFrame();
mf.setVisible(true);
}
添加回答
举报
0/150
提交
取消