2016-08-19 79 views
-6

它引发异常。 如何解决它。如何使其显示NULL或不空?

public class VaidateString { 

    public static void main(String[] args) { 
     String str = null; 
     if (str.equals(null)) { 
      System.out.println("It is NULL"); 
     } else { 
      System.out.println("Not Null"); 
     } 
    } 
} 
+1

它抛出了什么异常?这个例外并不能帮助你解决这个问题吗? – Gray

+0

使用==而不是“equals” – burakozgul

+0

if(str == null | str.length()== 0){' – d3r1ck

回答

0

str已经是空的,所以你不能调用它的方法。 if(str == null) should do