-5

when objec is null:

if(object != null && object.string.equals("")) {
    System.out.println("no error");
}

it will result in NullPointerException, and why if it checks the first result is false, it still check the second instead of stop check and print "no error"? sorry for my bad english -_-#

1 Answers1

3

It's not object which is null but object.string.

Try: (object != null && "".equals(object.string))

Grzegorz Piwowarek
  • 13,172
  • 8
  • 62
  • 93
  • 1
    thank you, and I find my mistake : before I take a judgement, I'm already Obeject object = new Obeject(); thank you for your answer again – 史书恒 Apr 26 '18 at 01:34