I have a Gradle project and I am trying to create a GUI (Swing, using Intellij); however, I keep receiving an error on compile. The exact same GUI code can be run on a standard Java project and compiles fine.
GUI
package gui;
import javax.swing.*;
public class ApplicationGUI {
private JPanel rootPanel;
private JLabel testLabel;
public static void main(String[] args) {
JFrame frame = new JFrame("ApplicationGUI");
frame.setContentPane(new ApplicationGUI().rootPanel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
}
Gradle
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile 'ca.uhn.hapi.fhir:hapi-fhir-base:3.7.0'
compile 'ca.uhn.hapi.fhir:hapi-fhir-structures-dstu3:3.7.0'
compile 'ca.uhn.hapi.fhir:hapi-fhir-client:3.7.0'
}
Error
Task :ApplicationGUI.main() FAILED
Exception in thread "main" java.awt.IllegalComponentStateException: contentPane cannot be set to null.
at javax.swing.JRootPane.setContentPane(JRootPane.java:621)
at javax.swing.JFrame.setContentPane(JFrame.java:698)
at gui.ApplicationGUI.main(ApplicationGUI.java:11)
In my settings I have the GUI Designer set to Java Source Code.
What am I doing wrong?
Cheers
EDIT1:
I can confirm that the above code works 100% fine with Maven..
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…