Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Exception thrown by the agent : java.lang.NullPointerException when starting Java application

Tags:

java

I am starting a Java application with the following command line arguments:

java -Dcom.sun.management.jmxremote.port=12312 \
     -Dcom.sun.management.jmxremote.rmi.port=12313 \
     -Dcom.sun.management.jmxremote.authenticate=false \
     Main

My program exits immediately and I get the following error:

Error: Exception thrown by the agent : java.lang.NullPointerException

I am using Java 8 update 45 on Windows 7:

java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
like image 375
K Erlandsson Avatar asked Jun 18 '15 06:06

K Erlandsson


People also ask

How do I fix Java Lang NullPointerException error?

In Java, the java. lang. NullPointerException is thrown when a reference variable is accessed (or de-referenced) and is not pointing to any object. This error can be resolved by using a try-catch block or an if-else condition to check if a reference variable is null before dereferencing it.

What does it mean when it says Java Lang NullPointerException?

The java. lang. NullPointerException is a runtime exception in Java that occurs when a variable is accessed which is not pointing to any object and refers to nothing or null. Since the NullPointerException is a runtime exception, it doesn't need to be caught and handled explicitly in application code.

What is NullPointerException in Java example?

NullPointerException is a runtime exception and it is thrown when the application try to use an object reference which has a null value. For example, using a method on a null reference.

Can we throw NullPointerException in Java?

You can also throw a NullPointerException in Java using the throw keyword.


1 Answers

This error occurs if com.sun.management.jmxremote.rmi.port is set to a port that is already in use. Try setting the property to a free port or killing the process that is currently using the port in question.

There is a reported bug here in Open JDK to improve this error message. It is fixed in Java 8 update 60 and Java 7 update 80.

like image 117
K Erlandsson Avatar answered Sep 22 '22 15:09

K Erlandsson