I'm creating new app in Intellij IDEA 13.1.4 Community Edition
I can run my app in IDE, but, when I create jar, after execute I get error:
java.awt.IllegalComponentStateException: contentPane cannot be set to null.
at javax.swing.JRootPane.setContentPane(JRootPane.java:620)
at javax.swing.JDialog.setContentPane(JDialog.java:1045)
at MainDialog.<init>(MainDialog.java:39)
at MainDialog.createAndShowUI(MainDialog.java:193)
at MainDialog.access$1200(MainDialog.java:13)
at MainDialog$13.run(MainDialog.java:184)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:733)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:694)
at java.awt.EventQueue$3.run(EventQueue.java:692)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:703)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
I have tried to search on google/stackoverflow
- How to launch swing app with jetbrains layouts in Netbeans
- http://grahamedgecombe.com/blog/using-intellij-ideas-javac2-in-gradle
- Intellij Idea 13 UI Designer and automatic Gradle building
and attached links in last post
Here is my sample code for MainDialog.java
public static void main(String[] args) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
createAndShowUI();
}
});
}
private static void createAndShowUI() {
System.out.println("Start");
JFrame frame = new JFrame("rConnect");
try {
frame.setContentPane(new MainDialog().getContentPane());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
} catch (IllegalComponentStateException e) {
e.printStackTrace();
} finally {
frame.pack();
frame.setVisible(true);
}
System.out.println("Finish");
}
and here is my build.gradle
apply plugin: 'java'
apply plugin: 'application'
mainClassName = 'com.test.rconnect'
version = '0.1'
sourceCompatibility = 1.7
repositories {
mavenCentral()
}
jar {
baseName = 'rConnect'
from files(sourceSets.main.output.classesDir)
from files(sourceSets.main.output.resourcesDir)
from { configurations.compile.collect { zipTree(it) } }
manifest {
attributes 'Implementation-Title': 'rConnect'
attributes 'Implementation-Version': version
attributes 'Main-Class': 'MainDialog'
}
}
sourceSets {
main {
java {
srcDir 'src/main/java'
}
resources {
srcDir 'src/main/resources'
}
}
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'org.apache.commons:commons-lang3:3.3.2'
compile 'org.apache.commons:commons-io:1.3.2'
compile 'commons-logging:commons-logging-api:1.1'
compile 'org.ini4j:ini4j:0.5.2'
}
I'm also experiencing strange behaviour of IDE
When I do clean > run app, it is running without problem.
When I do jar > run app, it crash with same error, until I do clean > run.
Any help ? Thank You.