Weird NullPointerException


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

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

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

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). (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.


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:)


Please sign in to leave a comment.