Problem after compiling an IDEA-project without IDEA

已回答

Hi!

I have written some code and after compiling it from inside IDEA everything works fine.

What I can´t do is compile and then run my code by using the command line. I get a NullPointerExeption when I try to start my compiled Application (the compilation works fine).
So compiling with and without IDEA must make a difference!? My Application includes a GUI.

Can anyone help??

Thanks a lot,
Oush

0
Avatar
Permanently deleted user

if you used IDEA's form designer, you have to include forms_rt.jar

0
Avatar
Permanently deleted user

Yes, I used IDEA´s GUI-Designer.
form_rt.jar is already included in IDEA under
File>Settings>Path-->Libraries(Classpath).

Unfortunately my Problem stays the same: After compiling my code with javac in the command line I get a NullPointerExeption when I try to run the compiled Application :(

Or do you mean something different with "include"!?

Thanks!

0
Avatar
Permanently deleted user

I just realized that a missing forms_rt.jar isn't the problem (actually, it will be, eventually, but you haven't hit it just yet :).

There are two things you need to do in order to run IDEA generated GUI outside of IDEA:

1) Make sure you have fully functioning form classes.

When running GUI projects under IDEA, by default it will compile the forms into byte code and then setup you environment so that these classes are loaded automatically when the program starts. OTOH, when you run your program from a command prompt, IDEA isn't there to do its behind the scenes magic and you have to make sure that the form classes are ready and present. The easiest way to do this is to go into Project Setup->GUI Designer and change GUI generation from "binary class file" to "Java source code", then (re)build your project. This will generate the necessary source code. After that you should no longer getting the NullPointerException.

2) Make sure forms_rt.jar is loaded when you run the project

Once you do (1) you will either get a compiler error (if you went the source code generation route) or a ClassDefNofFoundException when you try to run your code (if you used binary files). This is because, once again, IDEA isn't there to properly set up the environment. As you have mentioned, forms_rt.jar file is included in your project inside the IDE, but when you run your code outside IDEA, you have to include the jar manually (i.e. make sure that it's part of the classpath)

0
Avatar
Permanently deleted user

1) Done
2) Done

Everything works now with and without IDEA.

Thanks a lot!!!

0

Hello!

I used Mr. Dmitry's method and I got to the first part without any errors. On the second part though I got a different error, "NoClassDefFoundError".

I already included the rt_forms.jar and my other dependency files using:

" javac -cp libs/forms_rt.jar;libs/common-collections4-4.1.jar;libs/poi-3.17.jar;libs/poi-ooxml-3.17.jar;libs/poi-ooxml-schemas-3.17.jar;libs/xmlbeans-2.6.0.jar; *.java "

0

Hi Benjmerales,

Could you provide a complete error stacktrace?

Try to convert GUI forms into Java source code as per https://stackoverflow.com/a/13744911/12844632 and rebuild the project. 

Then add IDEA_HOME\lib\forms_rt.jar to the classpath and run the project from the command line.

0

请先登录再写评论。