• Post Reply Bookmark Topic Watch Topic
  • New Topic

nullpointer exception  RSS feed

 
nitin satish
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when i do SWING programs i am getting nullpointer exception.what should i do?
 
faisal usmani
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • 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
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • 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 ]
 
Campbell Ritchie
Marshal
Posts: 56598
172
  • Mark post as helpful
  • send pies
  • 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
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!