2016-08-19 77 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