• 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

nullpointer exception

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
when i do SWING programs i am getting nullpointer exception.what should i do?
 
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it's really not possible to tell why there is such an error unless an until we have that part of the programme can u be a little more specific by sharing that part of the programme.

regards
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Or even better... give us the exact null pointer exception message. The NPE message is very good at targeting the class, method, file, and line number where the error occured.

Henry
[ April 30, 2006: Message edited by: Henry Wong ]
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We have had this question before; the NullPointerException is one of the commonest. Look at this thread from the end of last year.
See whether it is of any help. There are several suggestions as to how to deal with such Exceptions. But what you ought not to be doing with most of at least these three Exceptions
  • NullPointerException
  • ArithmeticException
  • XYZIndexOutOfBoundsException
  • is to catch them, because they usually represent errors in the program somewhere.
    No, you need to find out where they are occurring and prevent them.

    NullPointerException means you have unintentionally forgotten to instantiate one of the objects, or (occasionally) have managed to destroy it without noticing.

    ...OutOfBoundsException means you haven't counted an array or String or something correctly and you are looking for a non-existent member.

    ArithmeticException usually means you are trying to divide or "%" by zero.

    If you ever have a method which deals with thoses situations and intentionally throws such an Exception, make sure you have a javadoc like thisCR
     
    reply
      Bookmark Topic Watch Topic
    • New Topic