Skip to main content

java.lang.NullPointerException What ?

1 reply [Last post]
Joined: 2008-01-25
Points: 0

Hi everyone ,

I'm just going crazy from the java.lang.NullPointerException , have any one at sun or the openJDK community thought about adding more information to this error ?

for example :

package test;
* @author alaa
public class NullHell {

* @param args the command line arguments
public static void main(String[] args) {
// TODO code application logic here

Integer a=50;
Integer b=100;
System.out.println("A+B:"+ ( a +b));

======This code is working fine=========

Now change the a to null like this:
Integer a=null;

Now, rerun the appliction and sure you get this :

Exception in thread "main" java.lang.NullPointerException
at test.NullHell.main(
Java Result: 1

And here you can't tell where is the error . (which one is null a or b ?)


Wouldn't be nice if they could tell something like this

Exception in thread "main" java.lang.NullPointerException(A==null)
at test.NullHell.main(

another example like ,
getCusomers().getOrders().getOrderByID(100).getOrderItem(0); , when u get NullPointerException in such a line, you have to go debug customers, orders , order Item and so on. You can't tell which method from those returning the null !

Any thoughts about this ?

And what with this primitive forum that you can't format your code in it !!!

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2009-04-20
Points: 0

Your error might have already a solution at this site: