• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to set a string to be null and then check it?  RSS feed

 
Ji-Hoon Jung
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I try to set a string to be null like this:

string abc = null;
then I try to check it
if
(abc == null){
}
then NullPointerException

anyone knows?
 
Tom Reilly
Rancher
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which line of code is the runtime complaining about? Also, it would help if you post all of your code using code tags. See UseCodeTags for help. The code that you posted has a compiler error so it won't run.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
{picky-teaching-mode-on} You are NOT "setting a string to be null"
You appear to be trying to set a String reference variable to null - as in
String abc = null; // No new String object exists at this point
If you use the right words the concepts become much easier.
{picky-teaching-mode-off}

Bill
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!