异步任务抛出并发修改例外? [英] Async Task throw ConCurrent Modification Exception?
本文介绍了异步任务抛出并发修改例外?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我后,我们呼吁这个methos放大或缩小了呼吁的AsyncTask的放大和缩小的谷歌地图为: -
I am calling AsyncTask on zoom-in and zoom-out of google map after zoom-in or zoom-out we are calling this methos as:-
public void doListing(String URL) {
mapView.getOverlays().clear();
ListURL = URL;
System.out.println("Inside dolist methods----"+URL);
Eyelidmessage("Loading...");
if(currenttask == null)
{
currenttask = new Mapdatatask();
currenttask.execute();
}
else if(currenttask != null && currenttask.getStatus()== AsyncTask.Status.FINISHED)
{
currenttask = null ;
currenttask = new Mapdatatask();
currenttask.execute();
}
else if(currenttask != null && currenttask.getStatus()== AsyncTask.Status.RUNNING)
{
Log.e("currenttask",""+currenttask.getStatus());
currenttask.cancel(true);
currenttask = null ;
currenttask = new Mapdatatask();
currenttask.execute();
}
else if(currenttask != null && currenttask.getStatus()== AsyncTask.Status.PENDING)
{
Log.e("currenttask",""+currenttask.getStatus());
currenttask.cancel(true);
currenttask = null ;
currenttask = new Mapdatatask();
currenttask.execute();
}
}
Mapdatatask()是的AsyncTask类: -
Mapdatatask() is an AsyncTask class As:-
private class Mapdatatask extends AsyncTask<Void, Void, Integer>
{
@Override
protected void onPreExecute()
{
arrayList= new ArrayList<Applicationdataset>();
}
@Override
protected Integer doInBackground(Void... params) {
System.out.println("----ListURL IN doin Background-----"+ListURL);
try
{
StringBuilder sb=new StringBuilder();
URL sourceUrl=new URL(ListURL);
InputStream inputStream=sourceUrl.openStream();
//add if necessary the PushBack measure to safeguard the intended purpose here if really happening
//that you can actually ascertain it by saving a local copy for inspection
BufferedReader br=new BufferedReader(new InputStreamReader(inputStream));
String line;
while ((line=br.readLine())!=null) {
sb.append(line+"\n");
}
br.close();
SAXParserFactory spff=SAXParserFactory.newInstance();
spff.setNamespaceAware(true);
SAXParser spp=spff.newSAXParser();
XMLReader xr=spp.getXMLReader();
myHandler=new ApplicationHandler();
xr.setContentHandler(myHandler);
System.out.println("resultttt-----"+sb.toString());
xr.parse(new InputSource(new StringReader(sb.toString())));
//xr.parse(new InputSource(sourceUrl.openStream()));
valueoftotal = ApplicationHandler.value;
arrayList = myHandler.getParsedData();
System.out.println("total value------"+valueoftotal);
}
catch(IOException e) {
e.printStackTrace();
} catch (SAXException e)
{
arrayList= new ArrayList<Applicationdataset>();
try
{
StringBuilder sb=new StringBuilder();
URL sourceUrl=new URL(ListURL);
InputStream inputStream=sourceUrl.openStream();
//add if necessary the PushBack measure to safeguard the intended purpose here if really happening
//that you can actually ascertain it by saving a local copy for inspection
BufferedReader br=new BufferedReader(new InputStreamReader(inputStream));
String line;
while ((line=br.readLine())!=null) {
sb.append(line+"\n");
}
br.close();
inputStream.close();
SAXParserFactory spff=SAXParserFactory.newInstance();
spff.setNamespaceAware(true);
SAXParser spp=spff.newSAXParser();
XMLReader xr=spp.getXMLReader();
myHandler=new ApplicationHandler();
xr.setContentHandler(myHandler);
xr.parse(new InputSource(new StringReader(sb.toString())));
//xr.parse(new InputSource(sourceUrl.openStream()));
valueoftotal = ApplicationHandler.value;
arrayList = myHandler.getParsedData();
//arrayList = myHandler.getParsedData();
}
catch(IOException e1) {
arrayList.clear();
e1.printStackTrace();
Log.e("parse exception0"," dont know why");
Log.e("XML Error ",e.toString());
} catch (SAXException e1)
{
arrayList.clear();
Log.e("parse exception1"," dont know why");
e1.printStackTrace();
} catch (ParserConfigurationException e1)
{
arrayList.clear();
Log.e("parse exception2"," dont know why");
e1.printStackTrace();
} catch (ParseException e1) {
Log.e("parse exception3"," dont know why");
e1.printStackTrace();
}
e.printStackTrace();
} catch (ParserConfigurationException e) {
arrayList.clear();
Log.e("parse exception2"," dont know why");
e.printStackTrace();
} catch (ParseException e) {
arrayList.clear();
Log.e("parse exception3"," dont know why");
e.printStackTrace();
}
return 1;
}
@Override
protected void onPostExecute(Integer result)
{
if(valueoftotal!=null && !valueoftotal.equalsIgnoreCase(""))
{
if(Integer.parseInt(valueoftotal) > 0 && Integer.parseInt(valueoftotal) <= 100)
{
OverlayItem oi =null;
if(myHandler.getParsedData()!=null)
{
myvectorlist = new Vector<ArrayList<Applicationdataset>>();
System.out.println(arrayList.size()+"++++++++++");
Map<Key, ArrayList<Applicationdataset>> mlistVector = groupTheList(arrayList);
myvectorlist = putIntoVector(mlistVector);
System.out.println("oh nioce----"+myvectorlist.size());
}
linearbottom2.setClickable(true);
mapOverlays.clear();
//overlay.removeAll();
overlay = new GoogleMapViewOverlay(drawable,mapView,activity);
lineartabbar.setBackgroundResource(R.drawable.mapbar);
if(myvectorlist != null && myvectorlist.size() > 1)
{
Applicationdataset data = null;
try {
for(int i = 0; i < myvectorlist.size(); i++)
{
data = myvectorlist.get(i).get(0);
String latvalue = data.getLatitude().toString();
String lonvalue = data.getLongitude().toString();
System.out.println("+++1 hhh+++");
GeoPoint point = null;
try
{
point = new GeoPoint((int)(Double.parseDouble(latvalue)*1E6),(int)(Double.parseDouble(lonvalue)*1E6));
}
catch (NumberFormatException e)
{
e.printStackTrace();
}
if(point != null)
{
System.out.println("Above size of arraylist---=="+overlay.size()+"======index of array"+i);
if(overlay.size() == i)
{
oi = overlay.createItem(i);
}
if(i>overlay.size())
{
Log.e("Error-------------", "Overlay size= "+overlay.size() + " index = "+i);
Log.e("Error-------------", "");
continue;
}
System.out.println("size of arraylist---=="+overlay.size()+"======index of array"+i);
if(overlay!=null && oi!=null)
{
overlay.addItem(oi);
if(myvectorlist.size() == 1)
{
mc.animateTo(point);
mc.setCenter(point);
mc.setZoom(16);
}
}
}
}//end for loop
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("+++size of overlay++++ "+overlay.size());
mapOverlays.add(overlay);
mapView.invalidate();
}
textViewpopup.setText(valueoftotal+" listings found.");
linearlayoutpopup.setVisibility(View.VISIBLE);
RunAnimationslisting();
}
else if(Integer.parseInt(valueoftotal) > 100)
{
Eyelidmessage(valueoftotal+" listings found. \n Zoom-in, press the locate button below or select the refine button above to display fewer properties. ");
lineartabbar.setBackgroundResource(R.drawable.mapwithoutlist);
linearbottom2.setClickable(false);
}
else if(Integer.parseInt(valueoftotal) == 0)
{
GoneAnimations();
lineartabbar.setBackgroundResource(R.drawable.mapwithoutlist);
linearbottom2.setClickable(false);
customizeDialog = new CustomizeDialog(activity);
customizeDialog.setTitle("Sorry");
customizeDialog.setMessage("No Listing Found");
customizeDialog.show();
}
}
super.onPostExecute(result);
}
很少,当我放大和缩小的谷歌地图引发此异常异常堆栈跟踪情况如下: -
Seldom when I am zoom-in and zoom-out google map throws this exception Exception Stack trace is as follow :-
06-29 10:27:26.100: E/AndroidRuntime(9683): FATAL EXCEPTION: main
06-29 10:27:26.100: E/AndroidRuntime(9683): java.util.ConcurrentModificationException
06-29 10:27:26.100: E/AndroidRuntime(9683): at java.util.ArrayList$ArrayListIterator.next(ArrayList.java:573)
06-29 10:27:26.100: E/AndroidRuntime(9683): at com.rentfaster.home.GoogleMapView.groupTheList(GoogleMapView.java:2305)
06-29 10:27:26.100: E/AndroidRuntime(9683): at com.rentfaster.home.GoogleMapView.access$1(GoogleMapView.java:2303)
06-29 10:27:26.100: E/AndroidRuntime(9683): at com.rentfaster.home.GoogleMapView$Mapdatatask.onPostExecute(GoogleMapView.java:1416)
06-29 10:27:26.100: E/AndroidRuntime(9683): at com.rentfaster.home.GoogleMapView$Mapdatatask.onPostExecute(GoogleMapView.java:1)
06-29 10:27:26.100: E/AndroidRuntime(9683): at android.os.AsyncTask.finish(AsyncTask.java:590)
06-29 10:27:26.100: E/AndroidRuntime(9683): at android.os.AsyncTask.access$600(AsyncTask.java:149)
06-29 10:27:26.100: E/AndroidRuntime(9683): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:603)
06-29 10:27:26.100: E/AndroidRuntime(9683): at android.os.Handler.dispatchMessage(Handler.java:99)
06-29 10:27:26.100: E/AndroidRuntime(9683): at android.os.Looper.loop(Looper.java:132)
06-29 10:27:26.100: E/AndroidRuntime(9683): at android.app.ActivityThread.main(ActivityThread.java:4126)
06-29 10:27:26.100: E/AndroidRuntime(9683): at java.lang.reflect.Method.invokeNative(Native Method)
06-29 10:27:26.100: E/AndroidRuntime(9683): at java.lang.reflect.Method.invoke(Method.java:491)
06-29 10:27:26.100: E/AndroidRuntime(9683): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
06-29 10:27:26.100: E/AndroidRuntime(9683): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
06-29 10:27:26.100: E/AndroidRuntime(9683): at dalvik.system.NativeStart.main(Native Method)
如何处理这种情况,请谁能帮助我尽快。
How I can Handle this situation please anyone help me ASAP.
推荐答案
您可以更改类的所有方法的 Mapdatatask
可同步的方法,再试试。
You can change all methods of your class Mapdatatask
to synchronized method, then try out.
例如从
protected Integer doInBackground(Void... params) {
....
}
要
protected synchronized Integer doInBackground(Void... params) {
....
}
做的所有方法都是一致的,并再次检查。 :)
Do the same for all methods and check again. :)
这篇关于异步任务抛出并发修改例外?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文