WulLaoGod 2019-09-21 21:24 采纳率: 50%
浏览 3133
已采纳

idea,gradle项目报错,解决不了/(ㄒoㄒ)/~~.

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 :classes

Task :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.

  • 写回答

1条回答 默认 最新

  • Json-Huang 2019-09-22 09:19
    关注

    new test().panel1为空导致,可以先给panel1的属性设置值,一般获取自身属性,不需要先new,直接传入字段名称即可,
    frame.setContentPane(new test().panel1);可以改成frame.setContentPane(panel1);

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 关于wordpress建站遇到的问题!(语言-php)(相关搜索:云服务器)
  • ¥15 【求职】怎么找到一个周围人素质都很高不会欺负他人,并且未来月薪能够达到一万以上(技术岗)的工作?希望可以收到写有具体,可靠,已经实践过了的路径的回答?
  • ¥15 Java+vue部署版本反编译
  • ¥100 对反编译和ai熟悉的开发者。
  • ¥15 带序列特征的多输出预测模型
  • ¥15 Python 如何安装 distutils模块
  • ¥15 关于#网络#的问题:网络是从楼上引一根网线下来,接了2台傻瓜交换机,也更换了ip还是不行
  • ¥15 资源泄露软件闪退怎么解决?
  • ¥15 CCF-CSP 2023 第三题 解压缩(50%)
  • ¥30 comfyui openpose报错