• Post Reply Bookmark Topic Watch Topic
  • New Topic

Need help with null pointer exception  RSS feed

 
Iskandar Zulkarnaen
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello guys, I'm new here.. I got a problem in my coding:


After I send the message to the receiver and got an error says that "message not send to the admin java.lang.NullPointerException". Any solutions? Thanks!
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch. When you post code, please use code tags. I've added them in your post above. Also, please indent your code properly. Maybe your original code was properly indented, but the formatting was lost when you posted it here? Anyway, if you indent your code properly, it is much easier to see the structure of the code, making working with the code much easier.

A NullPointerException happens when you try to call a method or access a member on a variable that is null. The exception message (stack trace) tells you exactly in which line the exception occurred. Carefully look at the stack trace to see where in your code it happened. Then look at that place in your code and think about what is null there that should not have been null.

If you don't see the stack trace, use this line:

in the catch block, rather than just this:
 
Knute Snortum
Sheriff
Posts: 4281
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch!

In your sendTo() method you have all the code wrapped in two try/catch blocks.  You can get rid of the outer one.

In addition to what Jesper said about printing stack traces, you may want to break that giant try/catch block into smaller blocks.  That way it is easier to see where the problem is and you can catch specific exceptions instead of the all-encompassing Exception.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!