使用迭代的时候,出现了java.lang.IllegalStateException

代码:

 for ( TaskInfo info : userTaskInfos ) {
if ( info.isChecked() ) {
am.killBackgroundProcesses(info.getPackageName());
if ( getPackageName().equals(info.getPackageName()) ) {
continue;
}
avaliMem = avaliMem + info.getMemSize();
runningTaskCount = runningTaskCount - 1;
userTaskInfos.remove(info) }
}

原因:迭代的时候,不能操作数据。

解决办法:

 List< TaskInfo > removeTasks = new ArrayList<>();

             for ( TaskInfo info : userTaskInfos ) {
if ( info.isChecked() ) {
am.killBackgroundProcesses(info.getPackageName());
if ( getPackageName().equals(info.getPackageName()) ) {
continue;
}
avaliMem = avaliMem + info.getMemSize();
runningTaskCount = runningTaskCount - 1;
removeTasks.add(info);
}
}
userTaskInfos.removeAll(removeTasks);

Bug:java.lang.IllegalStateException的更多相关文章

  1. response.sendRedirect 报 java.lang.IllegalStateException 异常的解决思路

    今天在进行代码开发的时候,出现了 java.lang.IllegalStateException异常,response.sendRedirect("./DEFAULT.html") ...

  2. JDK8 stream toMap() java.lang.IllegalStateException: Duplicate key异常解决(key重复)

    测试又报bug啦 接到测试小伙伴的问题,说是一个接口不返回数据了,好吧,虽然不是我写的接口任务落到头上也得解决,本地调试了一下,好家伙,直接抛了个异常出来,这又是哪位大哥喝醉了写的代码... Exce ...

  3. 大型网站技术架构(四)--核心架构要素 开启mac上印象笔记的代码块 大型网站技术架构(三)--架构模式 JDK8 stream toMap() java.lang.IllegalStateException: Duplicate key异常解决(key重复)

    大型网站技术架构(四)--核心架构要素   作者:13GitHub:https://github.com/ZHENFENG13版权声明:本文为原创文章,未经允许不得转载.此篇已收录至<大型网站技 ...

  4. IDEA配置Hystrix过程中报错: java.lang.IllegalStateException: No instances available for user-service

    最近在练习微服务架构中, 使用IDEA配置完Hystrix, 添加熔断方法后, 在浏览器中访问未启动的( 含有熔断方法注解 )的路径时, 报出了 : 500: No instances availab ...

  5. 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 双击启动失败, ...

  6. 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 ...

  7. 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 ...

  8. java.lang.IllegalStateException: getOutputStream() has already been called for this response

    ERROR [Engine] StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exceptionjava.lang ...

  9. 用java实现文件下载,提示java.lang.IllegalStateException: getOutputStream() has already been called for this response

    1. 用java实现文件下载,提示java.lang.IllegalStateException: getOutputStream() has already been called for this ...

随机推荐

  1. MVC初学 - The type or namespace name 'DbContext' could not be found

    问题: The type or namespace name 'DbContext' could not be found (are you missing a using directive or ...

  2. iOS的影片播放 MediaPlayer 和 AVPlayer(转)

    分类: Iphone2013-01-28 16:19 5230人阅读 评论(0) 收藏 举报 在iOS開發上,如果遇到需要播放影片,如開機動畫…,我們很習慣地會使用MediaPlayer來播放影片,因 ...

  3. js SVG

    Snap.svg Paths.js http://www.sitepoint.com/creating-animated-valentines-day-card-snap-svg/

  4. VS2013中设置大小写的快捷键

    1.我们在定义头文件时,通常需要定义: #ifndef  _MainMenu_H_#define  _MainMenu_H_ your code... #endif 我们需要将头文件名设置为大写的: ...

  5. .Net webservice动态调用

    直接贴代码吧 public class PmsService { /// <summary> /// pms接口 /// </summary> /// <param na ...

  6. mysql存储过程中字符串参数单引号

    注意:存储过程中单引号  ,四个单引号 SET @sql = CONCAT('select user_id into ',m_user_id,' from go_user where mobile = ...

  7. hadoop 技巧

    通过--config指定不同的集群 bin/hadoop --config ./conf_time/ dfs -ls /user/rd/*/for_*/ip_table/output/ rd下是都读写 ...

  8. CentOS中实现Nginx负载均衡和反向代理

    一.安装必要软件 负载均衡服务器:IP设置为192.168.1.10 Web服务器1:安装Apache或者Nginx,IP设置为192.168.1.11: Web服务器2:安装Apache或者Ngin ...

  9. Restore IP Addresses

    Given a string containing only digits, restore it by returning all possible valid IP address combina ...

  10. poj 1562 Oil Deposits (广搜,简单)

    题目 简单的题目,只是测试案例的输入后面可能有空格,所以要注意一下输入方式. #define _CRT_SECURE_NO_WARNINGS //题目的案例输入n,m后面有些貌似有空格... #inc ...