• Post Reply Bookmark Topic Watch Topic
  • New Topic

help me with mysterious null exception  RSS feed

 
Kay Lee
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe execution of the first block is having some side effect that's setting something to null for the second block. Or maybe you're mis-reading the stack trace and the NPE is not on the line you think it is.

you should break out the individual pieces of those long expressions and print them out.



That will help you figure out what's going on here.

However, in general, a better way to write that if to avoid NPE and to not have to do separate tests for "Ok" or "ok" (and assuming any combination of upper/lower case is fine) would be simply:
 
Kay Lee
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
im really just a mere beginner.thank you sir...ill try those.#thumbsUp
 
Kay Lee
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OMG...it works

that did the trick..
you sir is a legend..
 
Kay Lee
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sir,could you explain little more about why should i pass the value from method getTest_result() to another variable before can be used in the if statement? just want to learn more about java..
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sparrow Horn wrote:sir,could you explain little more about why should i pass the value from method getTest_result() to another variable before can be used in the if statement? just want to learn more about java..


It's not necessary and it doesn't change how your code behaves. I suggested simply as a way to print out the individual pieces of what was going into that long, multi-part statement where the NPE was occurring.

Doing so can also make your code more readable.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!