android maps:数组索引超出界限的异常
我有一项任务显示458个标记在Android地图中显示。 为了避免与性能相关的问题,我使用AsyncTask
实例更新地图上的数据。
这是我做的一个简短的场景。
ItemizedOverlay
类中 publishProgress
方法在地图中放置50个标记。 在第50次迭代之后,流程通过publishProgress
进入onProgressUpdate
,这里是我的onProgressUpdate
方法的代码
// MapOverLays = mapView.getOverlays();
//This line was called in asyc task's constructor
// Hello Overlay is an instance of ItemizedOverlay.
mapOverlays.add(helloOverLay);
//MapView.getController - Also called in Constructor
controller.setZoom(12);
controller.animateTo(centerPoint);
controller.setCenter(centerPoint);
此代码引发ArrayIndexOutOfBoundException
,并且logcat不显示我的模块中的任何类。 如果它阐述了我的问题,这里是logcat转储。
12-07 11:34:48.644: ERROR/AndroidRuntime(508): java.lang.ArrayIndexOutOfBoundsException
12-07 11:34:48.644: ERROR/AndroidRuntime(508): at com.google.android.maps.ItemizedOverlay.getIndexToDraw(ItemizedOverlay.java:211)
12-07 11:34:48.644: ERROR/AndroidRuntime(508): at com.google.android.maps.ItemizedOverlay.draw(ItemizedOverlay.java:240)
12-07 11:34:48.644: ERROR/AndroidRuntime(508): at com.google.android.maps.Overlay.draw(Overlay.java:179)
12-07 11:34:48.644: ERROR/AndroidRuntime(508): at com.google.android.maps.OverlayBundle.draw(OverlayBundle.java:42)
12-07 11:34:48.644: ERROR/AndroidRuntime(508): at com.google.android.maps.MapView.onDraw(MapView.java:476)
12-07 11:34:48.644: ERROR/AndroidRuntime(508): at android.view.View.draw(View.java:6535)
12-07 11:34:48.644: ERROR/AndroidRuntime(508): at android.view.ViewGroup.drawChild(ViewGroup.java:1531)
12-07 11:34:48.644: ERROR/AndroidRuntime(508): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
12-07 11:34:48.644: ERROR/AndroidRuntime(508): at android.view.ViewGroup.drawChild(ViewGroup.java:1529)
12-07 11:34:48.644: ERROR/AndroidRuntime(508): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
12-07 11:34:48.644: ERROR/AndroidRuntime(508): at android.view.View.draw(View.java:6538)
12-07 11:34:48.644: ERROR/AndroidRuntime(508): at android.widget.FrameLayout.draw(FrameLayout.java:352)
12-07 11:34:48.644: ERROR/AndroidRuntime(508): at android.view.ViewGroup.drawChild(ViewGroup.java:1531)
12-07 11:34:48.644: ERROR/AndroidRuntime(508): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
12-07 11:34:48.644: ERROR/AndroidRuntime(508): at android.view.ViewGroup.drawChild(ViewGroup.java:1529)
12-07 11:34:48.644: ERROR/AndroidRuntime(508): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
12-07 11:34:48.644: ERROR/AndroidRuntime(508): at android.view.View.draw(View.java:6538)
12-07 11:34:48.644: ERROR/AndroidRuntime(508): at android.widget.FrameLayout.draw(FrameLayout.java:352)
12-07 11:34:48.644: ERROR/AndroidRuntime(508): at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1830)
12-07 11:34:48.644: ERROR/AndroidRuntime(508): at android.view.ViewRoot.draw(ViewRoot.java:1349)
12-07 11:34:48.644: ERROR/AndroidRuntime(508): at android.view.ViewRoot.performTraversals(ViewRoot.java:1114)
12-07 11:34:48.644: ERROR/AndroidRuntime(508): at android.view.ViewRoot.handleMessage(ViewRoot.java:1633)
12-07 11:34:48.644: ERROR/AndroidRuntime(508): at android.os.Handler.dispatchMessage(Handler.java:99)
12-07 11:34:48.644: ERROR/AndroidRuntime(508): at android.os.Looper.loop(Looper.java:123)
12-07 11:34:48.644: ERROR/AndroidRuntime(508): at android.app.ActivityThread.main(ActivityThread.java:4363)
12-07 11:34:48.644: ERROR/AndroidRuntime(508): at java.lang.reflect.Method.invokeNative(Native Method)
12-07 11:34:48.644: ERROR/AndroidRuntime(508): at java.lang.reflect.Method.invoke(Method.java:521)
12-07 11:34:48.644: ERROR/AndroidRuntime(508): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
12-07 11:34:48.644: ERROR/AndroidRuntime(508): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
12-07 11:34:48.644: ERROR/AndroidRuntime(508): at dalvik.system.NativeStart.main(Native Method)
PS我已经用相对较小(10)和相对较大(150)迭代而不是50测试了应用程序。但是应用程序抛出相同的错误。
我有同样的问题。 看起来是因为更新了ItemizedOverlay中的数据而未调用之后populate
引起的。
public class ListOverlay extends ItemizedOverlay<OverlayItem> {
...
public synchronized void updateLocations(List<OverlayItem> newLocations) {
locations.clear();
locations.addAll(newLocations);
populate(); // this was missing
}
protected synchronized OverlayItem createItem(int index) {
return locations.get(index);
}
public synchronized int size() {
return locations.size();
}
}
setLastFocusedIndex(-1); 填充();
不“始终”工作!
我暂时得到解决方案。 我不是经常添加引脚,而是首先准备整个数据,然后使用onPostExecute()将其添加到映射中,如上所述Android 2.1 GoogleMaps ItemizedOverlay ConcurrentModificationException,但它仍不符合我节省加载所有引脚的时间的要求。 不过,我可以摆脱这种例外。 但等待任何改善加载时间的建议....谢谢无论如何... :-)
链接地址: http://www.djcxy.com/p/49219.html