Mon application fonctionne très bien avec Android 1.6, mais quand je l'exécute sur Android 2.2, je reçois concurrModificationException à certains endroits. Après avoir enveloppé ma tête pendant des jours, j'ai trouvé une théorie: je suppose que le multi-threading (ou quelque chose de similaire) a été introduit depuis la version 1.6. Cela pourrait-il être cela? Si oui, est-ce un moyen de forcer l'application à s'exécuter sans le multi-thread? J'ai essayé de fixer la cible à 1,6, mais pas de chance ... D'avance, je voudrais vous remercier pour votre temps.Android mise à niveau de 1,6 à 2,2 entraîne des exceptions
Exception:
04-05 11:47:12.812: ERROR/AndroidRuntime(5328): FATAL EXCEPTION: main
04-05 11:47:12.812: ERROR/AndroidRuntime(5328): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { cmp=ntnu.client/com.google.android.maps.MapView (has extras) }} to activity {ntnu.client/ntnu.client.MapClient}: java.util.ConcurrentModificationException
04-05 11:47:12.812: ERROR/AndroidRuntime(5328): at android.app.ActivityThread.deliverResults(ActivityThread.java:3808)
04-05 11:47:12.812: ERROR/AndroidRuntime(5328): at android.app.ActivityThread.handleSendResult(ActivityThread.java:3850)
04-05 11:47:12.812: ERROR/AndroidRuntime(5328): at android.app.ActivityThread.access$2800(ActivityThread.java:136)
04-05 11:47:12.812: ERROR/AndroidRuntime(5328): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2209)
04-05 11:47:12.812: ERROR/AndroidRuntime(5328): at android.os.Handler.dispatchMessage(Handler.java:99)
04-05 11:47:12.812: ERROR/AndroidRuntime(5328): at android.os.Looper.loop(Looper.java:143)
04-05 11:47:12.812: ERROR/AndroidRuntime(5328): at android.app.ActivityThread.main(ActivityThread.java:5068)
04-05 11:47:12.812: ERROR/AndroidRuntime(5328): at java.lang.reflect.Method.invokeNative(Native Method)
04-05 11:47:12.812: ERROR/AndroidRuntime(5328): at java.lang.reflect.Method.invoke(Method.java:521)
04-05 11:47:12.812: ERROR/AndroidRuntime(5328): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-05 11:47:12.812: ERROR/AndroidRuntime(5328): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-05 11:47:12.812: ERROR/AndroidRuntime(5328): at dalvik.system.NativeStart.main(Native Method)
04-05 11:47:12.812: ERROR/AndroidRuntime(5328): Caused by: java.util.ConcurrentModificationException
04-05 11:47:12.812: ERROR/AndroidRuntime(5328): at java.util.ArrayList$ArrayListIterator.next(ArrayList.java:573)
04-05 11:47:12.812: ERROR/AndroidRuntime(5328): at ntnu.client.MapClient.handleResult(MapClient.java:599)
04-05 11:47:12.812: ERROR/AndroidRuntime(5328): at ntnu.client.MapClient.onActivityResult(MapClient.java:881)
04-05 11:47:12.812: ERROR/AndroidRuntime(5328): at android.app.Activity.dispatchActivityResult(Activity.java:3988)
04-05 11:47:12.812: ERROR/AndroidRuntime(5328): at android.app.ActivityThread.deliverResults(ActivityThread.java:3804)
04-05 11:47:12.812: ERROR/AndroidRuntime(5328): ... 11 more
Code avec handleResult-code est fourni ci-dessous.
public synchronized void handleResult(boolean notify)
{
if(!citynodes.equals(null) && citynodes.size()>0)
{
noteBaloon.setVisibility(0x00000008);
Drawable drawable = this.getResources().getDrawable(R.drawable.up);
Context myContext = this;
itemizedoverlay = new CitynodeItemizedOverlay(drawable,myContext);
itemizedoverlay.setThumbsUp(BitmapFactory.decodeResource(
getResources(), R.drawable.vote_yes3));
itemizedoverlay.setThubmsDown(BitmapFactory.decodeResource(
getResources(), R.drawable.vote_no3));
itemizedoverlay.addObserver(this);
//itemizedoverlay.setDoAnimtation(true);
RecommendationNotificationOverlay overlay = new RecommendationNotificationOverlay();
for (Recommendation n : citynodes)
{
CitynodeOverlayItem cn= n.getNode().getOverlayItem();
Drawable marker = this.iconmanager.changeBackground(this.iconmanager.findIcon(n.getNode()),Integer.parseInt(n.getSystemRating()),n.isPersonalized());
//marker.setAlpha(100);
marker.setBounds(0, 0, marker.getIntrinsicWidth(), marker.getIntrinsicHeight());
ShapeDrawable l;
cn.setMarker(marker);
cn.setNode(n);
itemizedoverlay.addOverlay(cn);
LayoutInflater inflater = getLayoutInflater();
}
for(Overlay i : getMapView().getOverlays())
{
if((i instanceof ItemizedOverlay)) //|| (i instanceof RecommendationNotificationOverlay))
this.mapView.getOverlays().remove(i);
}
for(Overlay i : getMapView().getOverlays())
{
if((i instanceof RecommendationNotificationOverlay))
this.mapView.getOverlays().remove(i);
}
List <Recommendation> proactive = new ArrayList<Recommendation>();
for(Recommendation potpro : this.citynodes)
{
if(potpro.isProactive())
{
proactive.add(potpro);
}
}
overlay.setNotifications(proactive);
mapOverlays.add(overlay);
mapOverlays.add(itemizedoverlay);
mapView.invalidate();
}
}
Le code de cette exception fait référence est la première boucle for:
for(Overlay i : getMapView().getOverlays())
Le code jette également la même exception à cette ligne (traitement une autre action):
if(!citynodes.equals(null) && citynodes.size()>0)
pouvez-vous fournir le journal de ces erreurs? puisque la mise à niveau vers la version 2.2 à partir de la version 1.6 ne devrait pas poser de problème –
L'erreur n'est pas due à thread.did vous avez une erreur dans vos programmes? –
Android a toujours eu le multithreading, mais 2.2 introduit JIT qui donne quelques améliorations de vitesse, et peut avoir causé le minutage entre vos threads de changer où précédemment vous avez eu la chance qu'il n'a pas montré sa tête. – Nick