1
Hi I have a map application where I need to show all the markers fetched from database onto map it is don on pressing a button. It shows perfectly for the pressing once but if i press the button twice then it gives ConcurrentModificationException. Any help would be appreciated. Here is my asynctask class for loading the markers onto map from database.

    class LoadMarkers extends AsyncTask<Void , Void , Void>
        {

            ProgressDialog progressDialog;

            @Override
            protected void onPreExecute() 
            {

                progressDialog = ProgressDialog.show(DemoAccidentReport.this , "Loading Markers" , "Please wait..." , true , false);
                Log.d("after progress dialog onPreExecute()------->" , "onPreExecute()");
                super.onPreExecute();
            }

            @Override
            protected Void doInBackground(Void... params)
            {

                Log.d("after progress dialog doInBackground()------->" , "doInBackground()");

                try
                {
                    db = openOrCreateDatabase("LocationFetch.db", MODE_PRIVATE , null);

                    cursor = db.rawQuery("SELECT * FROM user" , null);

                    drawableOne = getResources().getDrawable(R.drawable.location_blue);

                    final List<Overlay> mapOverlays = mapView.getOverlays();
                    //helloItemizedOverlay = new HelloItemizedOverlay(drawableOne , DemoAccidentReport.this);           
                    //helloItemizedOverlay = new HelloItemizedOverlay(drawableOne);

                    popUpitemizedOverlay = new MyPopupItemizedOverlay(drawableOne, mapView);
                    Log.d("after progress dialog doInBackground() One------->" , "doInBackground()");

                    //itemizedOverlay = new CustomItemizedOverlay<CustomOverlayItem>(drawableOne , mapView);

                    Log.d("after progress dialog doInBackground()Two------->" , "doInBackground()");

                    while(cursor.moveToNext())
                    {

                        int dataID = cursor.getColumnIndex("id");

                        String dataString = cursor.getString(0);
                        Log.d("ID DATA FROM DATABASE---->" , dataString);

                        String dataNAME = cursor.getString(1).toString().trim();
                        Log.d("NAME DATA FROM DATABASE---->", dataNAME);

                        String dataDESCRIPTION = cursor.getString(6);
                        Log.d("DESCRIPTION--------->" , dataDESCRIPTION);

                        String dataLAT = cursor.getString(2).toString().trim();
                        //Log.d("LAT DATA FROM DATABASE----->" , dataLAT);

                        double latitude = Double.parseDouble(dataLAT)*1000000;
                        Log.d("LATDOUBLE DATA FROM DATABASE----->" , latitude+"");

                        String dataLON = cursor.getString(3).toString().trim();
                        //Log.d("LONDOUBLE DATA FROM DATABASE----->" , dataLON);

                        double longitude = Double.parseDouble(dataLON)*1000000;
                        Log.d("LONDOUBLE DATA FROM DATABASE----->" , longitude+"");


                        //Image at column 4

                        //byte[] picture = cursor.getBlob(4);

                        ByteArrayInputStream inputStream = new ByteArrayInputStream(cursor.getBlob(4));

                        Bitmap bitmap = BitmapFactory.decodeStream(inputStream);

                        //showLatLon(latitude , longitude , dataNAME);
                        //ArrayList<OverlayItem> items = new ArrayList<OverlayItem>();
                        //OverlayItem[] markerItem = {new OverlayItem(new GeoPoint(latitude, longitude) , ""+dataNAME , ""+dataString)};
                        //OverlayItem markerItem = new OverlayItem(new GeoPoint((int)(latitude *1E6), (int)(longitude *1E6)) , ""+dataNAME , ""+dataString);\
                        //helloItemizedOverlay.addOverlay(overlayItem);
                        //mapView.getOverlays().add(helloItemizedOverlay);
                        //mapOverlays.add(helloItemizedOverlay);

                        /*CustomOverlayItem overlayItem = new CustomOverlayItem(new GeoPoint((int)(latitude *1E6), (int)(longitude *1E6)), ""+dataLAT , ""+dataLON , R.drawable.icon);
                        itemizedOverlay.addOverlay(overlayItem);
                        mapOverlays.add(itemizedOverlay);*/



                        //-------WORKING POPUP ONLY TITLE AND DESCRIPTION------//

                        OverlayItem overlayItem = new OverlayItem(new GeoPoint((int)latitude , (int)longitude) , ""+dataNAME , ""+dataDESCRIPTION /*null*/ );

                        popUpitemizedOverlay.addOverlay(overlayItem);

                        mapView.getOverlays().add(popUpitemizedOverlay);

                        mapOverlays.add(popUpitemizedOverlay);


                    }

                }catch(SQLException e)
                {
                    e.printStackTrace();                
                }finally
                {
                    cursor.close();
                }

                db.close();

                return null;
            }

            @Override
            protected void onPostExecute(Void result) 
            {
                progressDialog.dismiss();

                super.onPostExecute(result);
            }


        }

这是 logcat 的异常,它向我抛出了 Concurrent ModificationException 异常,在按下两次按钮时,即使它没有显示第一个标记,也只显示第二个标记:

04-10 14:05:14.898: E/AndroidRuntime(8991): FATAL EXCEPTION: main
04-10 14:05:14.898: E/AndroidRuntime(8991): java.util.ConcurrentModificationException
04-10 14:05:14.898: E/AndroidRuntime(8991):     at java.util.ArrayList$ArrayListIterator.next(ArrayList.java:576)
04-10 14:05:14.898: E/AndroidRuntime(8991):     at com.google.android.maps.OverlayBundle.draw(OverlayBundle.java:41)
04-10 14:05:14.898: E/AndroidRuntime(8991):     at com.google.android.maps.MapView.onDraw(MapView.java:530)
04-10 14:05:14.898: E/AndroidRuntime(8991):     at android.view.View.draw(View.java:6880)
04-10 14:05:14.898: E/AndroidRuntime(8991):     at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
04-10 14:05:14.898: E/AndroidRuntime(8991):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
04-10 14:05:14.898: E/AndroidRuntime(8991):     at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
04-10 14:05:14.898: E/AndroidRuntime(8991):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
04-10 14:05:14.898: E/AndroidRuntime(8991):     at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
04-10 14:05:14.898: E/AndroidRuntime(8991):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
04-10 14:05:14.898: E/AndroidRuntime(8991):     at android.view.View.draw(View.java:6986)
04-10 14:05:14.898: E/AndroidRuntime(8991):     at android.widget.FrameLayout.draw(FrameLayout.java:357)
04-10 14:05:14.898: E/AndroidRuntime(8991):     at android.widget.ScrollView.draw(ScrollView.java:1683)
04-10 14:05:14.898: E/AndroidRuntime(8991):     at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
04-10 14:05:14.898: E/AndroidRuntime(8991):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
04-10 14:05:14.898: E/AndroidRuntime(8991):     at android.view.View.draw(View.java:6883)
04-10 14:05:14.898: E/AndroidRuntime(8991):     at android.widget.FrameLayout.draw(FrameLayout.java:357)
04-10 14:05:14.898: E/AndroidRuntime(8991):     at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
04-10 14:05:14.898: E/AndroidRuntime(8991):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
04-10 14:05:14.898: E/AndroidRuntime(8991):     at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
04-10 14:05:14.898: E/AndroidRuntime(8991):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
04-10 14:05:14.898: E/AndroidRuntime(8991):     at android.view.View.draw(View.java:6883)
04-10 14:05:14.898: E/AndroidRuntime(8991):     at android.widget.FrameLayout.draw(FrameLayout.java:357)
04-10 14:05:14.898: E/AndroidRuntime(8991):     at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1940)
04-10 14:05:14.898: E/AndroidRuntime(8991):     at android.view.ViewRoot.draw(ViewRoot.java:1527)
04-10 14:05:14.898: E/AndroidRuntime(8991):     at android.view.ViewRoot.performTraversals(ViewRoot.java:1264)
04-10 14:05:14.898: E/AndroidRuntime(8991):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1865)
04-10 14:05:14.898: E/AndroidRuntime(8991):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-10 14:05:14.898: E/AndroidRuntime(8991):     at android.os.Looper.loop(Looper.java:130)
04-10 14:05:14.898: E/AndroidRuntime(8991):     at android.app.ActivityThread.main(ActivityThread.java:3687)
04-10 14:05:14.898: E/AndroidRuntime(8991):     at java.lang.reflect.Method.invokeNative(Native Method)
04-10 14:05:14.898: E/AndroidRuntime(8991):     at java.lang.reflect.Method.invoke(Method.java:507)
04-10 14:05:14.898: E/AndroidRuntime(8991):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
04-10 14:05:14.898: E/AndroidRuntime(8991):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
04-10 14:05:14.898: E/AndroidRuntime(8991):     at dalvik.system.NativeStart.main(Native Method)
4

0 回答 0