- for 循环语句中 Exception 问题汇总
- 错误: 找不到或无法加载主类 HomeWork04.
- 原因: java.lang.ClassNotFoundException: HomeWork04.
- 解决方案:删去HomeWork04后面那个点。
-
数组索引越界• ArrayIndexOutOfBoundsException• 访问到了数组中的不存在的索引时发生。
-
空指针异常• NullPointerException• 数组引用没有指向实体,却在操作实体中的元素时。
- 错误: 找不到或无法加载主类 HomeWork04.
- ClassCastException:类型转换异常
- 一般在多态的向下转型中容易出现
- NoSuchElementException:没有这样的元素,因为你已经找到最后了。
- // NoSuchElementException 不要多次使用it.next()方法,因为每次使用都是访问一个对象。
// System.out.println(((Student) it.next()).getName() + "---"
// + ((Student) it.next()).getAge());
转载于:https://my.oschina.net/u/4049480/blog/3010740