Intellij executes but java cant??

已回答

I am currently using 1.8.0 with intellij and it executes fine. But when i try to compile the exact same source code with "java" command line

 

i am currently trying to seek help on a java related problem but it seems something funny is going on. My question is located here...

 

http://www.javaprogrammingforums.com/whats-wrong-my-code/40979-issue-sending-value-new-pane-2.html

 

Source files can be downloaded at https://mega.nz/#!4FgQBABS!520OwtgJ0z_t6AeW3XbS9xAd1R-LllK01uIbLWBoPhE

 

with javac it compiles fine, but when i execute i get this error with MainPage

 

C:\Users\Syn\Desktop\testing\src>java MainPage
Exception in thread "main" java.awt.IllegalComponentStateException: contentPane
cannot be set to null.
at javax.swing.JRootPane.setContentPane(JRootPane.java:621)
at javax.swing.JDialog.setContentPane(JDialog.java:1047)
at MainPage.<init>(MainPage.java:19)
at MainPage.main(MainPage.java:36)

0

When using designer .forms and you build the project by IDE it instruments the source code when binding java source class to a designer form. This code is not present in the .java file. To see what actually is generated enabled generation of GUI form into the source code rather than binary classes:

Then IDE will generate the actual source code in the .java file and you will be able to compile and run it by standalone javac/java.

0
Avatar
Permanently deleted user

This is the error i got after trying to compile with javac. I have switched to java source code in editor > GUI designer.

0

The forms_rt.jar from IDE_HOME/lib directory must be added to the classpath.

0
Avatar
Permanently deleted user

i dropped forms_rt.jar in the same folder with all the .java files but im still getting the same error.

 

0
Avatar
Permanently deleted user

i checked the errors in intellij...

 

[code]

panel.setLayout(new com.intellij.uiDesigner.core.GridLayoutManager(4, 3, new Insets(0, 0, 0, 0), -1, -1));

[/code]

 

intellij is in red..

0

>i dropped forms_rt.jar in the same folder with all the .java files but im still getting the same error.

This will not add it to the classpath. To add the jar to the classpath when you compile from command line use "-cp" javac option, see https://stackoverflow.com/a/2096298/2000323

0
Avatar
Permanently deleted user

ok so working from the same directory as in the picture above, i tried entering the command

 

"javac MainPage.java -cp forms_rt.jar"

 

and im getting compile errors...

[code]

C:\Users\Syn\Desktop\testing\src>javac MainPage.java -cp forms_rt.jar
MainPage.java:23: error: cannot find symbol
Index zero = new Index();
^
symbol: class Index
location: class MainPage
MainPage.java:23: error: cannot find symbol
Index zero = new Index();
^
symbol: class Index
location: class MainPage
MainPage.java:27: error: cannot find symbol
Index2 one = new Index2();
^
symbol: class Index2
location: class MainPage
MainPage.java:27: error: cannot find symbol
Index2 one = new Index2();
^
symbol: class Index2
location: class MainPage
4 errors

[/code]

0

>"javac MainPage.java -cp forms_rt.jar"

When you use -cp option you must list all the jars and directories for it. Here you missed the current directory, which can be referenced via "." Use this command:

"javac MainPage.java -cp forms_rt.jar:." or "javac MainPage.java -cp forms_rt.jar;." (i.e. with ";" separator).

2
Avatar
Permanently deleted user

"javac MainPage.java -cp forms_rt.jar;." worked great. Ill be putting this on a brief hiatus until i can resolve my primary issue from the other forums.

 

 

 

1
Avatar
Permanently deleted user

 

https://intellij-support.jetbrains.com/hc/en-us/community/posts/360000100984/comments/360000066210

 

@Andrey-Dernov

 

 

Sorry, but did you run your compiled source?

Cause I have errors like this when running my Java source.

I've enabled Java GUI source code build instead of Binary Class File.

>> java crm -cp forms_rt.jar
 (this won't work either)
>> java crm
Exception in thread "main" java.lang.NoClassDefFoundError: com/intellij/uiDesigner/core/GridLayoutManager
       at crm.$$$setupUI$$$(crm.java:55)
       at crm.<init>(crm.java:43)
       at crm.main(crm.java:27)
Caused by: java.lang.ClassNotFoundException: com.intellij.uiDesigner.core.GridLayoutManager
       at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
       at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
       at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
       at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
       ... 3 more

But I don't know why having this problem.

1
Avatar
Permanently deleted user

What I'm trying to do is,
Compile and run Swing (GridLayout-intellij) without Intellij IDEA.

Just to build and execute with only java and javac.

I've succeed with build, but I cannot execute my swing application due to upper error.
Any solutions?

1

You need to make sure that forms_rt.jar is in the classpath when your run your app. Refer to the java command syntax.

0

请先登录再写评论。