我正在开发一个小手势应用程序,用于创建手势并将其保存到文件中,并基于android示例中的gestureBuilder代码。
我想删除存储在文件中的所有手势,代码的移植就像这样
private static GestureLibrary sStore;
final GestureLibrary store = sStore;
if (store.load())
{
for (String name : store.getGestureEntries())
{
for (Gesture gesture : store.getGestures(name))
{
final NamedGesture namedGesture = new NamedGesture();
namedGesture.gesture = gesture;
namedGesture.name = name;
sStore.removeGesture(namedGesture.name, namedGesture.gesture);
sStore.save();
}
}
}
但是在运行时,这给出了像这样的例外
03-13 14:42:07.009:E / AndroidRuntime(905):致命异常:主要 03-13 14:42:07:09:E / AndroidRuntime(905):java.util.ConcurrentModificationException 03-13 14:42:07:09:E / AndroidRuntime(905):at java.util.HashMap $ HashIterator.nextEntry(HashMap.java:796) 03-13 14:42:07.009:E / AndroidRuntime(905):at java.util.HashMap $ KeyIterator.next(HashMap.java:823) 03-13 14:42:07.009:E / AndroidRuntime(905):at com.likith.gesturebuilder.GestureBuilderActivity $ 2 $ 1.onClick(GestureBuilderActivity.java:127) 03-13 14:42:07.009:E / AndroidRuntime(905):at com.android.internal.app.AlertController $ ButtonHandler.handleMessage(AlertController.java:159) 03-13 14:42:07:09:E / AndroidRuntime(905):在android.os.Handler.dispatchMessage(Handler.java:99) 03-13 14:42:07:09:E / AndroidRuntime(905):在android.os.Looper.loop(Looper.java:123) 03-13 14:42:07:09:E / AndroidRuntime(905):在android.app.ActivityThread.main(ActivityThread.java:3683) 03-13 14:42:07.009:E / AndroidRuntime(905):at java.lang.reflect.Method.invokeNative(Native Method) 03-13 14:42:07.009:E / AndroidRuntime(905):at java.lang.reflect.Method.invoke(Method.java:507) 03-13 14:42:07:00:E / AndroidRuntime(905):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:839) 03-13 14:42:07:00:E / AndroidRuntime(905):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 03-13 14:42:07:09:E / AndroidRuntime(905):at dalvik.system.NativeStart.main(Native Method)
是否有任何方法可以从手势文件中删除所有手势 请帮忙......
答案 0 :(得分:0)
1)如果要删除手势库文件的所有手势(条目):
@Html.DisplayFor(m => m.Rating)
2)如果您只想删除一个条目:
if (store.load()) {
try {
List list = new ArrayList();
for (String name : store.getGestureEntries()) {
list.add(name);
}
for (int i = 0; i < list.size(); i++) {
store.removeEntry(list.get(i).toString());
store.save();
}
}catch (Exception e){
System.out.println(e.getMessage());
}
}
我希望它适合你。