import javax.swing.*;
public class test {
private JPanel panel1;
public static void main(String[] args) {
JFrame frame = new JFrame("test");
frame.setContentPane(new test().panel1);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
}
//自动生成的方法,第六行会报错,注释掉能运行......
报错信息:
Gradle Daemon started in 2 s 140 ms
Task :compileJava
Task :processResources NO-SOURCE
Task :classesTask :test.main() FAILED
Exception in thread "main" java.awt.IllegalComponentStateException: contentPane cannot be set to null.
at java.desktop/javax.swing.JRootPane.setContentPane(JRootPane.java:598)
at java.desktop/javax.swing.JFrame.setContentPane(JFrame.java:679)
at test.main(test.java:8)
FAILURE: Build failed with an exception.
-
What went wrong:
Execution failed for task ':test.main()'.Process 'command 'C:/Program Files/Java/jdk-12.0.2/bin/java.exe'' finished with non-zero exit value 1
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.2.1/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 6s
2 actionable tasks: 2 executed
21:15:23: External task execution finished ' 'test.main()''.
根据网上的教程搞得,以前可以运行,一顿操作后就报错了,更新版本,然后插件出了问题,卸载自己安装的插件.jdk一直是最新的12.