我有一个扩展 MapActivity 的类。
我使用名为 updateMap 的函数在地图上放置了大头针。大头针放置在基于加载的巴士站列表的位置。
我想在下载停止数组时显示一个加载对话框,但我的代码出现错误。我目前弹出对话框并生成一个线程来加载公交路线并更新地图。
经过一些研究,我开始意识到 UI 层不能从单独的线程更新。我试过移动东西,但似乎没有任何效果。
任何帮助表示赞赏!
private void updateMap(final int selectedRoute, final boolean isMajor, final boolean isMinor)
{
dlg = ProgressDialog.show(TransitMap.this, "Updating Map", "Processing... Please wait...");
new Thread()
{
public void run()
{
try
{
TransitMap.this.removePins();
TransitMap.this.addRoutePins(selectedRoute, isMajor, isMinor);
TransitMap.this.addBusPins(selectedRoute);
map.post(new Runnable()
{
public void run()
{
TransitMap.this.map.postInvalidate();
}
});
}
catch(Exception ex)
{
}
// processing done, hide progress dialog
dlg.dismiss();
}
}.start();
}
修改类以使用 AsyncTask 后,我的程序仍然崩溃!
这是 logCat 错误
04-13 15:16:49.217: E/AndroidRuntime(21898): FATAL EXCEPTION: main
04-13 15:16:49.217: E/AndroidRuntime(21898): java.util.ConcurrentModificationException
04-13 15:16:49.217: E/AndroidRuntime(21898): at java.util.ArrayList$ArrayListIterator.next(ArrayList.java:576)
04-13 15:16:49.217: E/AndroidRuntime(21898): at com.google.android.maps.OverlayBundle.draw(OverlayBundle.java:44)
04-13 15:16:49.217: E/AndroidRuntime(21898): at com.google.android.maps.MapView.onDraw(MapView.java:530)
04-13 15:16:49.217: E/AndroidRuntime(21898): at android.view.View.draw(View.java:6971)
04-13 15:16:49.217: E/AndroidRuntime(21898): at android.view.ViewGroup.drawChild(ViewGroup.java:1710)
04-13 15:16:49.217: E/AndroidRuntime(21898): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1437)
04-13 15:16:49.217: E/AndroidRuntime(21898): at android.view.ViewGroup.drawChild(ViewGroup.java:1708)
04-13 15:16:49.217: E/AndroidRuntime(21898): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1437)
04-13 15:16:49.217: E/AndroidRuntime(21898): at android.view.View.draw(View.java:6974)
04-13 15:16:49.217: E/AndroidRuntime(21898): at android.widget.FrameLayout.draw(FrameLayout.java:357)
04-13 15:16:49.217: E/AndroidRuntime(21898): at android.view.ViewGroup.drawChild(ViewGroup.java:1710)
04-13 15:16:49.217: E/AndroidRuntime(21898): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1437)
04-13 15:16:49.217: E/AndroidRuntime(21898): at android.view.ViewGroup.drawChild(ViewGroup.java:1708)
04-13 15:16:49.217: E/AndroidRuntime(21898): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1437)
04-13 15:16:49.217: E/AndroidRuntime(21898): at android.view.ViewGroup.drawChild(ViewGroup.java:1708)
04-13 15:16:49.217: E/AndroidRuntime(21898): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1437)
04-13 15:16:49.217: E/AndroidRuntime(21898): at android.view.ViewGroup.drawChild(ViewGroup.java:1708)
04-13 15:16:49.217: E/AndroidRuntime(21898): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1437)
04-13 15:16:49.217: E/AndroidRuntime(21898): at android.view.ViewGroup.drawChild(ViewGroup.java:1708)
04-13 15:16:49.217: E/AndroidRuntime(21898): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1437)
04-13 15:16:49.217: E/AndroidRuntime(21898): at android.view.View.draw(View.java:6974)
04-13 15:16:49.217: E/AndroidRuntime(21898): at android.widget.FrameLayout.draw(FrameLayout.java:357)
04-13 15:16:49.217: E/AndroidRuntime(21898): at android.view.ViewGroup.drawChild(ViewGroup.java:1710)
04-13 15:16:49.217: E/AndroidRuntime(21898): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1437)
04-13 15:16:49.217: E/AndroidRuntime(21898): at android.view.View.draw(View.java:6974)
04-13 15:16:49.217: E/AndroidRuntime(21898): at android.widget.FrameLayout.draw(FrameLayout.java:357)
04-13 15:16:49.217: E/AndroidRuntime(21898): at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1929)
04-13 15:16:49.217: E/AndroidRuntime(21898): at android.view.ViewRoot.draw(ViewRoot.java:1590)
04-13 15:16:49.217: E/AndroidRuntime(21898): at android.view.ViewRoot.performTraversals(ViewRoot.java:1290)
04-13 15:16:49.217: E/AndroidRuntime(21898): at android.view.ViewRoot.handleMessage(ViewRoot.java:1939)
04-13 15:16:49.217: E/AndroidRuntime(21898): at android.os.Handler.dispatchMessage(Handler.java:99)
04-13 15:16:49.217: E/AndroidRuntime(21898): at android.os.Looper.loop(Looper.java:143)
04-13 15:16:49.217: E/AndroidRuntime(21898): at android.app.ActivityThread.main(ActivityThread.java:4196)
04-13 15:16:49.217: E/AndroidRuntime(21898): at java.lang.reflect.Method.invokeNative(Native Method)
04-13 15:16:49.217: E/AndroidRuntime(21898): at java.lang.reflect.Method.invoke(Method.java:507)
04-13 15:16:49.217: E/AndroidRuntime(21898): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-13 15:16:49.217: E/AndroidRuntime(21898): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-13 15:16:49.217: E/AndroidRuntime(21898): at dalvik.system.NativeStart.main(Native Method)