问题描述
小伙子们
我从很多天面临非常奇怪的问题。我想经常更新覆盖。所以,有时我得到java.util.ConcurrentModificationException当我触摸地图上的某个或地图时,试图更新重叠但我没有找到它的这个错误是未来完美的线条得到。
02-17 14:56:01.621:W / dalvikvm(3653):主题ID = 1:螺纹退出与未捕获的异常(组= 0x40015560)
02-17 14:56:01.631:E / AndroidRuntime(3653):致命异常:主要
02-17 14:56:01.631:E / AndroidRuntime(3653):java.util.ConcurrentModificationException
02-17 14:56:01.631:E / AndroidRuntime(3653):在java.util.ArrayList中的$ ArrayListIterator.next(ArrayList.java:576)
02-17 14:56:01.631:E / AndroidRuntime(3653):在com.google.android.maps.OverlayBundle.draw(OverlayBundle.java:41)
02-17 14:56:01.631:E / AndroidRuntime(3653):在com.google.android.maps.MapView.onDraw(MapView.java:530)
02-17 14:56:01.631:E / AndroidRuntime(3653):在android.view.View.draw(View.java:6880)
02-17 14:56:01.631:E / AndroidRuntime(3653):在android.view.ViewGroup.drawChild(ViewGroup.java:1646)
02-17 14:56:01.631:E / AndroidRuntime(3653):在android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
02-17 14:56:01.631:E / AndroidRuntime(3653):在android.view.ViewGroup.drawChild(ViewGroup.java:1644)
02-17 14:56:01.631:E / AndroidRuntime(3653):在android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
02-17 14:56:01.631:E / AndroidRuntime(3653):在android.view.View.draw(View.java:6883)
02-17 14:56:01.631:E / AndroidRuntime(3653):在android.widget.FrameLayout.draw(FrameLayout.java:357)
02-17 14:56:01.631:E / AndroidRuntime(3653):在android.view.ViewGroup.drawChild(ViewGroup.java:1646)
02-17 14:56:01.631:E / AndroidRuntime(3653):在android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
02-17 14:56:01.631:E / AndroidRuntime(3653):在android.view.View.draw(View.java:6883)
02-17 14:56:01.631:E / AndroidRuntime(3653):在android.widget.FrameLayout.draw(FrameLayout.java:357)
02-17 14:56:01.631:E / AndroidRuntime(3653):在android.view.ViewGroup.drawChild(ViewGroup.java:1646)
02-17 14:56:01.631:E / AndroidRuntime(3653):在android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
02-17 14:56:01.631:E / AndroidRuntime(3653):在android.view.View.draw(View.java:6883)
02-17 14:56:01.631:E / AndroidRuntime(3653):在android.widget.FrameLayout.draw(FrameLayout.java:357)
02-17 14:56:01.631:E / AndroidRuntime(3653):在com.android.internal.policy.impl.PhoneWindow $ DecorView.draw(PhoneWindow.java:1862)
02-17 14:56:01.631:E / AndroidRuntime(3653):在android.view.ViewRoot.draw(ViewRoot.java:1522)
02-17 14:56:01.631:E / AndroidRuntime(3653):在android.view.ViewRoot.performTraversals(ViewRoot.java:1258)
02-17 14:56:01.631:E / AndroidRuntime(3653):在android.view.ViewRoot.handleMessage(ViewRoot.java:1859)
02-17 14:56:01.631:E / AndroidRuntime(3653):在android.os.Handler.dispatchMessage(Handler.java:99)
02-17 14:56:01.631:E / AndroidRuntime(3653):在android.os.Looper.loop(Looper.java:130)
02-17 14:56:01.631:E / AndroidRuntime(3653):在android.app.ActivityThread.main(ActivityThread.java:3683)
02-17 14:56:01.631:E / AndroidRuntime(3653):在java.lang.reflect.Method.invokeNative(本机方法)
02-17 14:56:01.631:E / AndroidRuntime(3653):在java.lang.reflect.Method.invoke(Method.java:507)
02-17 14:56:01.631:E / AndroidRuntime(3653):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:839)
02-17 14:56:01.631:E / AndroidRuntime(3653):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
02-17 14:56:01.631:E / AndroidRuntime(3653):在dalvik.system.NativeStart.main(本机方法)
我使用的气球覆盖
我觉得是在抛出错误mapview.getOverlay()
,因为它要求4-5倍在数秒。
谢谢
CapDroid
这里是code流..我的主题code ....
螺纹连接=新的Thread(){
公共无效的run(){
尝试 {
而(我的情况)
{
尝试
{
//此方法应该是调用每秒
updateMethod();
}
赶上(例外五)
{
e.printStackTrace();
打破;
}
}
}
赶上(例外五)
{
}
}
};
下面是我的updateMethod(); 在这code hashmapOverlay是一样的HashMap如下
公共静态地图<字符串,MyItemizedOverlay> hashmapOverlay;
公共无效updateMethod()
{
如果(hashmapOverlay.containsKey(ID))
{
。调用MapView.getOverlays()删除(hashmapOnlineFriendsOverlay.get(ID));
}
MyItemizedOverlay mMyItemizedOverlay =新MyItemizedOverlay(绘制,图形页面);
OverlayItem overlayItem =新OverlayItem(GP,标题段);
mMyItemizedOverlay.addOverlay(overlayItem);
hashmapOverlay.put(ID,mMyItemizedOverlay);
addOverlayMethod(mActivity,图形页面,mMyItemizedOverlay);
}
这是我的addOverlayMethod
addOverlayMethod(活动mActivity,最终的MapView MapView类,最终目标mObject)
{
mActivity.runOnUiThread(新的Runnable(){
@覆盖
公共无效的run()
{
尝试 {
MyItemizedOverlay覆盖=(MyItemizedOverlay)mObject;
。调用MapView.getOverlays()加入(重叠);
}赶上(例外五)
{}
}
});
}
你,你可以四处做工作,步骤如下。
- 请一个Pendingnotification类(modication细节)。
- 请在Pendingnotification的列表。
- 当任何通知接收DNT直接修改它,收集所有的修改,并把栈(Pendingnotification类)IE浏览器。在Pendingnotification列表中添加它。
- 现在,一个一个修改的对象和删除同一个对象时,它的完成工作。
同样的方式跟随,直到Pendingnotification列表变成空的。
和还指出,任何修改必须在 UI线程中执行
不是 NonUI主题
fellas
I am facing very strange issue from many days. I am trying to update overlay frequently. So sometime I am getting "java.util.ConcurrentModificationException" when I touch on map or sometime getting when map trying to update overlay But I am not finding perfect line which on this error is coming.
02-17 14:56:01.621: W/dalvikvm(3653): threadid=1: thread exiting with uncaught exception (group=0x40015560)
02-17 14:56:01.631: E/AndroidRuntime(3653): FATAL EXCEPTION: main
02-17 14:56:01.631: E/AndroidRuntime(3653): java.util.ConcurrentModificationException
02-17 14:56:01.631: E/AndroidRuntime(3653): at java.util.ArrayList$ArrayListIterator.next(ArrayList.java:576)
02-17 14:56:01.631: E/AndroidRuntime(3653): at com.google.android.maps.OverlayBundle.draw(OverlayBundle.java:41)
02-17 14:56:01.631: E/AndroidRuntime(3653): at com.google.android.maps.MapView.onDraw(MapView.java:530)
02-17 14:56:01.631: E/AndroidRuntime(3653): at android.view.View.draw(View.java:6880)
02-17 14:56:01.631: E/AndroidRuntime(3653): at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
02-17 14:56:01.631: E/AndroidRuntime(3653): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
02-17 14:56:01.631: E/AndroidRuntime(3653): at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
02-17 14:56:01.631: E/AndroidRuntime(3653): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
02-17 14:56:01.631: E/AndroidRuntime(3653): at android.view.View.draw(View.java:6883)
02-17 14:56:01.631: E/AndroidRuntime(3653): at android.widget.FrameLayout.draw(FrameLayout.java:357)
02-17 14:56:01.631: E/AndroidRuntime(3653): at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
02-17 14:56:01.631: E/AndroidRuntime(3653): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
02-17 14:56:01.631: E/AndroidRuntime(3653): at android.view.View.draw(View.java:6883)
02-17 14:56:01.631: E/AndroidRuntime(3653): at android.widget.FrameLayout.draw(FrameLayout.java:357)
02-17 14:56:01.631: E/AndroidRuntime(3653): at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
02-17 14:56:01.631: E/AndroidRuntime(3653): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
02-17 14:56:01.631: E/AndroidRuntime(3653): at android.view.View.draw(View.java:6883)
02-17 14:56:01.631: E/AndroidRuntime(3653): at android.widget.FrameLayout.draw(FrameLayout.java:357)
02-17 14:56:01.631: E/AndroidRuntime(3653): at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1862)
02-17 14:56:01.631: E/AndroidRuntime(3653): at android.view.ViewRoot.draw(ViewRoot.java:1522)
02-17 14:56:01.631: E/AndroidRuntime(3653): at android.view.ViewRoot.performTraversals(ViewRoot.java:1258)
02-17 14:56:01.631: E/AndroidRuntime(3653): at android.view.ViewRoot.handleMessage(ViewRoot.java:1859)
02-17 14:56:01.631: E/AndroidRuntime(3653): at android.os.Handler.dispatchMessage(Handler.java:99)
02-17 14:56:01.631: E/AndroidRuntime(3653): at android.os.Looper.loop(Looper.java:130)
02-17 14:56:01.631: E/AndroidRuntime(3653): at android.app.ActivityThread.main(ActivityThread.java:3683)
02-17 14:56:01.631: E/AndroidRuntime(3653): at java.lang.reflect.Method.invokeNative(Native Method)
02-17 14:56:01.631: E/AndroidRuntime(3653): at java.lang.reflect.Method.invoke(Method.java:507)
02-17 14:56:01.631: E/AndroidRuntime(3653): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
02-17 14:56:01.631: E/AndroidRuntime(3653): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
02-17 14:56:01.631: E/AndroidRuntime(3653): at dalvik.system.NativeStart.main(Native Method)
I am using Balloon Overlay
I think it is throwing error on "mapview.getOverlay()"
because it is calling 4-5 times in 1 seconds..
Thanks,
CapDroid
here is code flow..My Thread code....
Thread connection = new Thread(){
public void run() {
try {
while (my condition)
{
try
{
//This method should be call every seconds
updateMethod();
}
catch (Exception e)
{
e.printStackTrace();
break;
}
}
}
catch (Exception e)
{
}
}
};
Here is My updateMethod();in this code hashmapOverlay is HashMap like as below
public static Map<String,MyItemizedOverlay> hashmapOverlay;
public void updateMethod()
{
if(hashmapOverlay.containsKey(id))
{
mapview.getOverlays().remove(hashmapOnlineFriendsOverlay.get(id));
}
MyItemizedOverlay mMyItemizedOverlay = new MyItemizedOverlay(drawable, mapview);
OverlayItem overlayItem = new OverlayItem(gp,title ,snippet);
mMyItemizedOverlay.addOverlay(overlayItem);
hashmapOverlay.put(id, mMyItemizedOverlay);
addOverlayMethod(mActivity, mapView, mMyItemizedOverlay);
}
Here is my addOverlayMethod
addOverlayMethod(Activity mActivity, final MapView mapView, final Object mObject)
{
mActivity.runOnUiThread(new Runnable(){
@Override
public void run()
{
try {
MyItemizedOverlay overlay = (MyItemizedOverlay) mObject;
mapView.getOverlays().add(overlay);
} catch (Exception e)
{}
}
});
}
ya, you can do a work around,step as follow.
- Make a Pendingnotification class(modication detail).
- Make a list of the Pendingnotification.
- when any notification receive dnt modify it directly, Collect all the modification and put stack(Pendingnotification class) ie. add it in Pendingnotification list.
- now one by one modify the object and remove the same object when its work done.
same way follow untill Pendingnotification List become empty.
And also note that any modification must be perform in UI Thread
not in NonUI Thread
这篇关于java.util.ConcurrentModificationException在图形页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!