• Post Reply Bookmark Topic Watch Topic
  • New Topic

exception  RSS feed

 
Madhusudan Raju
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the console it is showing null pointer exception, but I don't know which file this exception is comming from? can you please help me how to find?
 
Anu Pillai
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are using the printStackTrace() method to get the trace of the exception, then it will show which line of which file is creating the exception. If you need help, then post the stack trace here and people will help you out.
 
Abhijith Prabhakar
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can include the whole area which you think is throwing NPE in a try block and catch it. After catching use printStackTrace(), which will show you the stack trace. eg
try{
arrList.size();//if you think here it is throwing NPE
//some statements

}catch(NullPointerException ne){
ne.printStackTrace();
}
Note: You should never catch a NPE. Instead before calling the method you should check for null. In the above case you should
if(arrList != null){
arrList.size();
}
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't have to catch the NPE to find out what file/line# is causing it. The text of the exception message should tell you that unambiguously. (It may however be a little more difficult to find out why a NPE occured) What is the full text of the exception message?
[ December 29, 2006: Message edited by: Garrett Rowe ]
 
fred rosenberger
lowercase baba
Bartender
Posts: 12542
48
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Those error messages are just chock full of usefull information besides the fact that "Something Went Wrong".

If you paste the EXACT text of the error message, we'll be happy to help you learn to read it. It's a good skill to have, not just for NPEs, but for ANY error message.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!