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)

  

posted @ 2012-01-13 14:02  一思  阅读(303)  评论(0编辑  收藏  举报