IllegalStateException
例1
public static void main(String[]sdf){
List<String> list = new ArrayList<String>();
list.add("1");
list.add("2");
list.add("3");
list.add("4");
Iterator<String> it = list.iterator();
if(it.hasNext()){
it.remove();
}
System.out.println(list.toString());
}
Console:
Exception in thread "main" java.lang.IllegalStateException
at java.util.ArrayList$Itr.remove(Unknown Source)
例2
public static void main(String[]sdf){
List<String> list = new ArrayList<String>();
list.add("1");
list.add("2");
list.add("3");
list.add("4");
Iterator<String> it = list.iterator();
if(it.hasNext()){
it.next();
it.remove();
}
System.out.println(list.toString());
}
Console:
[2, 3, 4]
例3
public static void main(String[]sdf){
List<String> list = new ArrayList<String>();
list.add("1");
list.add("2");
list.add("3");
list.add("4");
Iterator<String> it = list.iterator();
if(it.hasNext()){
it.next();
it.next();
it.remove();
}
System.out.println(list.toString());
}
Console:
[1, 3, 4]
例4
public static void main(String[]sdf){
List<String> list = new ArrayList<String>();
list.add("1");
list.add("2");
list.add("3");
list.add("4");
Iterator<String> it = list.iterator();
if(it.hasNext()){
it.next();
it.remove();
it.remove();
}
System.out.println(list.toString());
}
Console:
Exception in thread "main" java.lang.IllegalStateException
at java.util.ArrayList$Itr.remove(Unknown Source)
附:
remove
void remove()
- 从迭代器指向的 collection 中移除迭代器返回的最后一个元素(可选操作)。每次调用 next 只能调用一次此方法。如果进行迭代时用调用此方法之外的其他方式修改了该迭代器所指向的 collection,则迭代器的行为是不确定的。
-
- 抛出:
UnsupportedOperationException- 如果迭代器不支持 remove 操作。IllegalStateException- 如果尚未调用 next 方法,或者在上一次调用 next 方法之后已经调用了remove 方法。
IllegalStateException的更多相关文章
- myeclipse 无法启动 java.lang.IllegalStateException: Unable to acquire application service. Ensure that the org.eclipse.core.runtime bundle is resolved and started (see config.ini).
把myeclipse10 按照目录完整拷贝到了另外一台电脑, 另外的目录 原安装目录 D\:\soft\i\myeclipse10 新安装目录 E\:\soft\myeclipse10 双击启动失败, ...
- java.lang.IllegalStateException:Couldn't read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xxx...}: java.lang.IllegalSta ...
- java.lang.IllegalStateException: Cannot add header view to list -- setAdapter has already been called.
分析:android 4.2.X及以下的版本,addHeaderView必须在setAdapter之前,否则会抛出IllegalStateException. android 4.2.X(API 17 ...
- java.lang.IllegalStateException: Not allowed to create transaction on shared EntityManager - use Spring transactions or EJB CMT instead
java.lang.IllegalStateException: Not allowed to create transaction on sharedEntityManager - use Spri ...
- java.lang.IllegalStateException: getOutputStream() has already been called for this response
ERROR [Engine] StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exceptionjava.lang ...
- 用java实现文件下载,提示java.lang.IllegalStateException: getOutputStream() has already been called for this response
1. 用java实现文件下载,提示java.lang.IllegalStateException: getOutputStream() has already been called for this ...
- eclipse启动报错java.lang.IllegalStateException: LifecycleProcessor not initialized - call 'refresh' befo
报错: java.lang.IllegalStateException: LifecycleProcessor not initialized - call 'refresh' before invo ...
- java.lang.IllegalStateException: Couldn't read row 1, col 0 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data fr
Android中操作Sqlite遇到的错误:java.lang.IllegalStateException: Couldn't read row 1, col 0 from CursorWindow. ...
- java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
在ViewPager中,用Fragment显示页面时,报错: java.lang.IllegalStateException: The specified child already has a pa ...
- IllegalStateException : Web app root system property already set to different value问题详解
一.问题描述 最近公司有了一个新项目,这个项目最近部署到测试服务器上的时候出现了一个问题. 严重: Exception sending context initialized event to ...
随机推荐
- ajax连接数据库并操作数据库
Response.Write("<script type='text/javascript' language='javascript' >alert('用户名不能为空!请输入 ...
- ecshop 设置管理员
<?php define('IN_ECS', true); require(dirname(__FILE__) . '/includes/init.php'); $admin_name=trim ...
- 【英语】Bingo口语笔记(5) - 英式和美式英语的发音区别
- JBPM4入门——8.等待节点的分支执行
JBPM入门系列文章: JBPM4入门——1.jbpm简要介绍 JBPM4入门——2.在eclipse中安装绘制jbpm流程图的插件 JBPM4入门——3.JBPM4开发环境的搭建 JBPM4入门—— ...
- 基于CentOS与VmwareStation10搭建Oracle11G RAC 64集群环境:4.安装Oracle RAC FAQ-4.4.无法图形化安装Grid Infrastructure
无法图形化安装: [grid@linuxrac1 grid]$ ./runInstaller Starting Oracle Universal Installer... Checking Temp ...
- Spring3.0.6定时任务
项目使用的Spring版本比较旧是3.0.6版本,由于需要进行定时任务,就决定使用Spring自带的scheduled task. 在网上找了很多文章,也查看了Spring3.0.6的官方文档,按照网 ...
- A+B for Matrices 及 C++ transform的用法
题目大意:给定两个矩阵,矩阵的最大大小是M*N(小于等于10),矩阵元素的值的绝对值小于等于100,求矩阵相加后全0的行以及列数. #include<iostream> using nam ...
- 《C++ primer》--第1,2章小结
来源:http://blog.csdn.net/wangqiulin123456/article/details/8483853 1.变量初始化: 定义变量时,应该给变量赋初始值,除非确定将 ...
- PHP 优化详解
笔者收集的这些技巧来源较广,完整性不能保证. 由于数量较多,这些优化技巧没有经过测试.请各位看官在使用之前自行测试,毕竟这些技巧是否能派上用场,还是需要由PHP所在的独特环境所决定的. 目录索引 找到 ...
- Autodesk Stingray 游戏引擎
Autodesk的游戏引擎质量够高的. http://v.youku.com/v_show/id_XMTMwMjc0MDIwMA==.html?qq-pf-to=pcqq.group http://v ...