NullPointerException 空指针异常
所谓空指针异常就是当对象为null时,调用了它的属性或者方法,就会报NullPointerException
package test; public class Test { public String test = "abd"; public void test(){ System.out.println("test"); } public static void main(String[] args) { Test t = null; System.out.println(t.test); t.test(); } }
结果如下:
Exception in thread "main" java.lang.NullPointerException at test.Test.main(Test.java:12)