Weird NullPointerException

Answered

Here is my problem: I want to run a java application called GetMagic.java, here is my commands in terminal:

javac -classpath path1/javabuilder.jar:path2/makesqr.jar ./GetMagic.java

java -classpath path1/javabuilder.jar:path2/makesqr.jar GetMagic 5

The result is:

Which means this java application was successfully compiled and run.

However, when I tried to run this application in Intellij 2016, I got weird NullPointerException.

I use the same jdk and jar packages in both terminal and Intellij


I'll highly appreciate that if anyone can help solve this problem. Thanks

2 comments
Comment actions Permalink

Did you specify the command line argument in the Application run/debug configuration? It appears that your app fails with NPE when there is no parameter passed ("5" in your command line example).

https://www.jetbrains.com/help/idea/2016.1/creating-and-editing-run-debug-configurations.html
https://www.jetbrains.com/help/idea/2016.1/run-debug-configuration-application.html (specify 5 in Program Arguments field).

Add some code that would check if the app is started with empty arguments to display a user friendly message instead of failing with NPE.

 

0
Comment actions Permalink

I've found the answer! There is nothing wrong with IntelliJ, turns out that intelliJ can not automatically add environment variable files(such as .bash_profile) which my project needs to use. I should explicitly set the environment variables in intelliJ to avoid the NPE. Thanks anyway:)

0

Please sign in to leave a comment.