天天看点

黑马程序员_011_常见异常

-------  android培训、 java培训、期待与您交流! ---------- 1、ArithmeticException,数学异常 2、ArrayIndexOutOfBoundsException,数组角标越界异常 3、NullPointerException,空指针异常 4、InterruptedException    :Thread类中提供了该方法interrupt().注意:使用了interrupt(),会抛异常InterruptedException   因此需要  try  catch(InterruptedException e) 处理,在处理语句中操作标记 5、ConcurrentModificationException List集合特点有的迭代器,ListIterator是Iterator的子接口。 在迭代时,不可以通过集合对象的方法操作集合中的元素,因为会发生并发修改异常:ConcurrentModificationException,所以,在迭代器时,只能用迭代器的方法操作元素,可是Iterator方法是优先的,只能对元素进行判断,取出,删除的操作。 如果想要其他的操作如添加、修改等,就需要使用其子接口,ListITerator。 该接口只能通过List集合的listIterator()方法获取。 6、NoSuchElementsException LinkedList 特有方法: getFirst(); getLast();只取不删 removeFirst();取并删 removeLast(); 注意当linkedList 为空时,进行上述操作,抛出异常NoSuchElementsException

1.6版本后出现替代方法 offerFirst();//添加元素 offerLast(); peekFirst();//获取元素,但不删除,如果集合没有元素,返回null,不抛异常 peekLast(); pollFirst();//获取元素,并在链表中删除,如果集合中没有元素,返回null,而不是抛异常 pollLast();

7、ClassCastException,类之间转换时出现的异常,强制类型转换。 8、java.lang.UnsupportedClassVersionError:Bad version number in .class file 解释:一个工作间workspace 包含多个java工程,我们可以为整个workspace设置JRE(windows--preferences--java--Compiler(编译时JRE)和Installed JREs(运行时JRE)),也可以为单独一个java工程设置JRE(右键工程--Properties--Java Compiler),当单独java工程JRE与java工程 run as--Run Configurations--JRE的版本不一致时就会出现上述错误。只要把二者JRE版本一致即可解决。

继续阅读