• Post Reply Bookmark Topic Watch Topic
  • New Topic

URGENT: NullPointerException  RSS feed

 
ada choi
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When i tried to run and connect the application to a server (which in this case, its my computer ip add), the Wireless Toolkit shows an error "Uncaught exception java/lang/NullPointerException"

What shld i do?
Please help, its really urgent. Thank you.
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A NullPointerException means that you're accessing a field or calling a method on a null reference (usually uninitialized). You can wrap your code (in the main method usually) with a try-catch block and print the stack trace of the exception. That will tell you where the problem is happening, and you can investigate from there. If you don't know how to do this, ask in the Beginner's forum.

Here are a few other pieces of advice, too:

Once you get the exception stack trace, post again with information that will allows us to help you: the stack trace itself (including the full error message) and the code that causes the exception with enough context (surrounding code) that demonstrates what's happening.

Read this page of advice about posting "URGENT" messages. In summary, it often has the opposite effect by turning people away!

The other links on How to ask questions the smart way are very good advice as well.
[ January 30, 2005: Message edited by: David Harkness ]
 
ada choi
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply.
So that means, there is something wrong with the codings?

i'm sorry for not reading the advice page. Thanks for the reminder!!
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you've got a bug. The following code will cause a NPE.A null pointer exception means that you've told the JVM to call a method on a non-existent object.

It would be like me telling you to launch your space shuttle. Could you? No, since you don't have one (okay, I'm making a huge assumption here ). The NPE is Java's way of telling you that you don't have a space shuttle.

Since your code doesn't catch it, the JVM exits and prints it out. Normally you don't handle null pointer exceptions. Instead, you make sure that you initialize all of your objects before using them. The above code could be fixed by setting nullString to an actual string, for example:
[ January 30, 2005: Message edited by: David Harkness ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!