vendredi 27 mars 2015

Avoid Concurent modification exception [duplicate]




This question already has an answer here:




I trying to debug few code and gives Concurent modification exception


code



final GestureLibrary store1 = GestureLibraries.fromFile(new File(Environment.getExternalStorageDirectory(), "Gesture_launcher"));

if (store1.load())
{
for (String name : store1.getGestureEntries())
{
for (Gesture gesture : store1.getGestures(name))
{
if(name.contains(gesture_name))
{
store1.removeGesture(name, gesture);
store1.addGesture(name, mGesture);
store1.save();

Toast.makeText(getApplicationContext(), getResources().getString(R.string.saved), Toast.LENGTH_LONG).show();
}
}
}
}


Executing the above statement gives concurrentModificationException


Logcat



03-28 02:47:45.422: E/AndroidRuntime(449): FATAL EXCEPTION: main
03-28 02:47:45.422: E/AndroidRuntime(449): java.util.ConcurrentModificationException
03-28 02:47:45.422: E/AndroidRuntime(449): at java.util.HashMap$HashIterator.nextEntry(HashMap.java:796)
03-28 02:47:45.422: E/AndroidRuntime(449): at java.util.HashMap$KeyIterator.next(HashMap.java:823)
03-28 02:47:45.422: E/AndroidRuntime(449): at com.likith.gesturebuilder.change_gestures.setGestures(change_gestures.java:69)
03-28 02:47:45.422: E/AndroidRuntime(449): at com.likith.gesturebuilder.change_gestures$1.onClick(change_gestures.java:110)
03-28 02:47:45.422: E/AndroidRuntime(449): at android.view.View.performClick(View.java:2485)
03-28 02:47:45.422: E/AndroidRuntime(449): at android.view.View$PerformClick.run(View.java:9080)
03-28 02:47:45.422: E/AndroidRuntime(449): at android.os.Handler.handleCallback(Handler.java:587)
03-28 02:47:45.422: E/AndroidRuntime(449): at android.os.Handler.dispatchMessage(Handler.java:92)
03-28 02:47:45.422: E/AndroidRuntime(449): at android.os.Looper.loop(Looper.java:123)
03-28 02:47:45.422: E/AndroidRuntime(449): at android.app.ActivityThread.main(ActivityThread.java:3683)
03-28 02:47:45.422: E/AndroidRuntime(449): at java.lang.reflect.Method.invokeNative(Native Method)
03-28 02:47:45.422: E/AndroidRuntime(449): at java.lang.reflect.Method.invoke(Method.java:507)
03-28 02:47:45.422: E/AndroidRuntime(449): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-28 02:47:45.422: E/AndroidRuntime(449): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-28 02:47:45.422: E/AndroidRuntime(449): at dalvik.system.NativeStart.main(Native Method)


Please tell any method on how to avoid this exception Thank you




Aucun commentaire:

Enregistrer un commentaire