1.数组下边越界异常:java.lang.ArrayIndexOutOfBoundsException
1、@Test
public void test1() {
int[] i = new int[10];
System.out.println(i[10]);
}2、 int[] i = new int[10];
for (int j = 0; j <= i.length; j++) { //出现等号最大长度为length,则数组越界,最大长度为11,出现异常
System.out.println(i[j]);
}
2.算术异常:java.lang.ArithmeticException
@Test
public void test2() {
int i = 10;
System.out.println(i / 0);
}
3.类型转换异常:java.lang.ClassCastException
@Test
public void test3() {
Object obj = new Date();
String str = (String)obj;
//String str1 = (String)new Date();编译时出错
}
4.空指针异常:java.lang.NullPointerException
1、@Test
public void test4() {
TestError p = new TestError();
p = null;
System.out.println(p.toString());
}2、 boolean[] b = new boolean[3];
b = null;
System.out.println(b[0]);