• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

exception

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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();
}
 
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
My honeysuckle is blooming this year! Now to fertilize this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic