Bug:java.lang.IllegalStateException

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

代码:

 1 for ( TaskInfo info : userTaskInfos ) {
 2                 if ( info.isChecked() ) {
 3                     am.killBackgroundProcesses(info.getPackageName());
 4                     if ( getPackageName().equals(info.getPackageName()) ) {
 5                         continue;
 6                     }
 7                     avaliMem = avaliMem + info.getMemSize();
 8                     runningTaskCount = runningTaskCount - 1;
 9                     userTaskInfos.remove(info)
10
11                 }
12             }

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

解决办法:

 1 List< TaskInfo > removeTasks = new ArrayList<>();
 2
 3             for ( TaskInfo info : userTaskInfos ) {
 4                 if ( info.isChecked() ) {
 5                     am.killBackgroundProcesses(info.getPackageName());
 6                     if ( getPackageName().equals(info.getPackageName()) ) {
 7                         continue;
 8                     }
 9                     avaliMem = avaliMem + info.getMemSize();
10                     runningTaskCount = runningTaskCount - 1;
11                     removeTasks.add(info);
12                 }
13             }
14             userTaskInfos.removeAll(removeTasks);
时间: 2024-10-29 09:32:59

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

bug java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState

在有Fragment的Activity中开启Activity出现下面这个Exception: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceStateat android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1343)at android.support.v4.app.Frag

Java.lang.IllegalStateException Activity has been destroyed

03-04 12:01:05.468: E/AndroidRuntime(2474): FATAL EXCEPTION: main03-04 12:01:05.468: E/AndroidRuntime(2474): java.lang.IllegalStateException: Activity has been destroyed03-04 12:01:05.468: E/AndroidRuntime(2474):     at android.support.v4.app.Fragmen

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

今天在进行代码开发的时候,出现了 java.lang.IllegalStateException异常,response.sendRedirect("./DEFAULT.html"); 这一条语句出错. 在网上进行查找之后,发现问题很有可能是因为response.sendRedirect方法执行了两次,其中一次肯定是项目框架里面的跳转,而我自己要进行跳转的话,就显得极其不方便,最后我把目光放到前端页面,在前端页面进行跳转. 一开始我的前端语句是:window.location.href=

常见错误之java.lang.IllegalStateException: The application’s PagerAdapter changed the adapter’s cont。。。

如果在logcat日志中出现以下错误: java.lang.IllegalStateException: The application's PagerAdapter changed the adapter's contents without calling PagerAdapter#notifyDataSetChanged! Expected adapter item count: 0, found: 4 Pager id: com.activity_test.logo:id/viewpag

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

测试又报bug啦 接到测试小伙伴的问题,说是一个接口不返回数据了,好吧,虽然不是我写的接口任务落到头上也得解决,本地调试了一下,好家伙,直接抛了个异常出来,这又是哪位大哥喝醉了写的代码... Exception in thread "main" java.lang.IllegalStateException: Duplicate key at java.util.stream.Collectors.lambda$throwingMerger$0(Collectors.java:133)

java.lang.IllegalStateException: Failed to load ApplicationContext

1.错误描述 INFO:2015-02-05 22:14:21[main] - Loading XML bean definitions from class path resource [applicationContext.xml] INFO:2015-02-05 22:14:22[main] - JSR-250 'javax.annotation.ManagedBean' found and supported for component scanning INFO:2015-02-05

java.lang.IllegalStateException: ContainerBase.addChild: start

java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina] Tomcat部署Servlet时出错 caused by: Caused by: java.lang.IllegalArgumentException: Invalid <url-patt

开发中遇到的问题(一)——java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

1.错误描述: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. 2.起因: 在Manifest中设置我的activity全屏 1 <activity android:name=".SplashActivity" 2 android:theme="@android:style/Theme.Black.No

java.lang.IllegalStateException: Illegal access: this web application instance has been stopped already.

java.lang.IllegalStateException: Illegal access: this web application instance has been stopped already. Could not load [META-INF/services/javax.xml.bind.JAXBContext]. 解决方法:先将项目remove,然后停止服务器,到应用程序目录下将部署的应用删除,然后启动服务器,重新部署就ok了 原因:暂不明确,可能是修改后有原来的残留物.