1.NullPointerException 空指针异常
空指针异常非常常见,在业实际务场景中经常出现
String ss=null;
ss.equals("str");
2.ArrayIndexOutOfBoundsException 数组索引越界异常
ArrayList中只有1个数据,最大索引是0,当获取下标为1的数时,就会ArrayIndexOutOfBoundsException
ArrayList arrayList = new ArrayList();
arrayList.add(1);
arrayList.get(1);
或者
int []arr = new int[3];
System.out.println(arr[3]);
3.ArithmeticException 数学计算异常
比如 0做分母时,会提示ArithmeticException: / by zero
int a = 1/0;
4.NumberFormatException 字符串转换为数字异常
将非数字字符串转换成非数字时
String str = "#";
Integer.valueOf(str);
5.ClassCastException 类型强制转换异常
将object类强转为Integer时会报此异常(强转只能向上)
Object object = new Object();
Integer integer = (Integer)object;
将Integer类型转换成String时
Object y = new Integer(0);
System.out.println((String)y);
其他的runtimeException 可以去java源码中找 寻找方法是看该类是否继承了 RuntimeException