使用迭代的时候,出现了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. matlab实现插值法sin函数

    插值法实现sin函数: %calculate and print the sine function %input: x %output: sin(x) similar function y = si ...

  2. c语言编程之栈(链表实现)

    用链表实现栈,完成了出栈入栈功能. #include"stdio.h" typedef int element; //define a struct descirbe a stac ...

  3. 【转】 Android经验: proguard 阻碍 webview 正常工作

    转自:http://blog.csdn.net/span76/article/details/9065941 WebView 常识 使用 Alert  提供消息 我在页面经常用 Alert 提供消息, ...

  4. Django 学习笔记之六 建立一个简单的博客应用程序

    最近在学习django时建立了一个简单的博客应用程序,现在把简单的步骤说一下.本人的用的版本是python 2.7.3和django 1.10.3,Windows10系统 1.首先通过命令建立项目和a ...

  5. Basic Concepts of International Trade

    The international trade structure is a reflection of worldwide economic development, industrial stru ...

  6. MAC 13信道

    房东的路由器一直连不上,手机却能连上,前天设置了13信道,后来又忘了,最后找到个连接WIFI的方法,在网络偏好设置里选择向导,诊断中可以连上wifi.

  7. MyEclipse2015破解版_MyEclipse 2015 stable 2.0 稳定版 破解日志

    前言:在MyEclipse 2015 Stable 1.0下载安装破解日志(http://www.cnblogs.com/wql025/p/5161979.html)一文中,笔者主要讲述了该版本的破解 ...

  8. [luogu 1880]石子合并

    题目描述 在一个园形操场的四周摆放N堆石子,现要将石子有次序地合并成一堆.规定每次只能选相邻的2堆合并成新的一堆,并将新的一堆的石子数,记为该次合并的得分. 试设计出1个算法,计算出将N堆石子合并成1 ...

  9. effect state dx11

    一个blendstate { BlendEnable[0]=TRUE; SrcBlend[0]=ONE; DestBlend[]=ONE; BlendOp[0]=ADD; } [0]-----一次混合 ...

  10. 《head first java 》读书笔记(三)

    Updated 2014/04/03 --P518 Thread需要任务,任务是实现过Runnable的实例.Runnalbe这个接口只有一个方法.run()会是新线程所执行的第一项方法.要把Runn ...