Hi,
I've a basic question in Java. If i have a code like
String str = null;
System.out.println(str.length);
The above code will throw a nullpointer exception. Is there a way to find out that str is the variable that threw the null pointer exception?
Thanks,
Eshwari
-
A question in Java (3 messages)
- Posted by: Eshwari PattapathuSubramanianSundaran
- Posted on: August 29 2005 13:23 EDT
Threaded Messages (3)
- A question in Java by beton beton on August 29 2005 15:42 EDT
- A question in Java | use java debug for this by Abhijeet Mahalkar on September 27 2005 03:34 EDT
- A question in Java by Ruslan Zenin on September 28 2005 13:57 EDT
-
A question in Java[ Go to top ]
- Posted by: beton beton
- Posted on: August 29 2005 15:42 EDT
- in response to Eshwari PattapathuSubramanianSundaran
use:
if(str!= null) {
System.out.println(str.length);
} else {
System.out.println("str is nul");
}
or, use assertions, or maybe you dont have to know that str is null. -
A question in Java | use java debug for this[ Go to top ]
- Posted by: Abhijeet Mahalkar
- Posted on: September 27 2005 03:34 EDT
- in response to beton beton
you can use JDB utility of JAVA to debug the java code properly. Hope this iwll help
abhijeet mahalkar -
A question in Java[ Go to top ]
- Posted by: Ruslan Zenin
- Posted on: September 28 2005 13:57 EDT
- in response to Eshwari PattapathuSubramanianSundaran
Hi,I've a basic question in Java. If i have a code likeString str = null;System.out.println(str.length);The above code will throw a nullpointer exception. Is there a way to find out that str is the variable that threw the null pointer exception?Thanks,Eshwari
The exception trace stack should point to the line of your code that did generate this NPE. In most cases, this should be sufficient to figure out the problem...