常见的运行时异常如下:
(1) 类型转换异常 ClassCastException
String strName=new string(“123”); int nNumber=(int)strName;
(2) 数组超界异常
ArrayIndexOutBoundsException
int[] b=new int[10];
b[10]=1000;
(3) 指定数组维数为负值异常
NegativeArraySizeException
b[-1]=1001;
(4) 算术异常ArithmeticException
int b=0; a=500/b;
(5) Java系统内部异常InternalException JVM抛出的异常。
(6) 类型不符合异常IncompatibleTypeException
int n=12345; String s=(String)n;
(7) 内存溢出异常OutOfMemeoryException
(8) 没有找到类定义异常
NoClassDefFoundException aClass aa=new aClas(); //但aClass类未定义。
(9) 空指针异常NullPointerException
int b[ ]; b[0]=99; //没有实例化,就访问,将产生空指 针。