尝试将手势保存到GestureLibrary时出现问题

时间:2012-02-06 14:56:44

标签: android gestures

我正在从目录中的文件构建手势,并尝试将它们保存在手势库中。 我无法正确地帮助

class B implements Runnable
         {
            File main;
            B(File temp)
            {
                main=temp;
            }
             public void savegesture()
                {
                    final GestureLibrary store=sStore;
                    for(int i=0;i<list.size();i++)
                    {
                        try{
                        String name="0"+i;
                        store.addGesture(name, list.get(i));
                        store.save();
                        }catch(Exception e)
                        {
                            System.out.println("error");
                        }
                    }
                }

            public void run()
            {

                File[] newfiles=main.listFiles();
                 File[] temp=null;
                 int progress=0;
                 float dircnt=0;

                 int numberoffiles=newfiles.length;
                 for(File b:newfiles)
                 {
                    try{
                        Gesture gest;

                            gest=dotask.batchprocess(b);
                         if(gest!=null)
                         {
                             System.out.println("success");
                            list.add(gest);
                         }

                    }catch(Exception e)
                    {
                        System.out.println("error saving file");
                    }



                      savegesture();



                 }
            }
         }
        public void addgestures()
        {
            cView.postInvalidate();
            dotask.setH(cView.getH());
            dotask.setW(cView.getW());

            count=0;
           B b=new B(dir);

           Thread t=new Thread(b);
           t.start();

} 任何人都可以说我的LogCat错误在哪里我无法理解。

02-06 20:25:18.269: E/AndroidRuntime(31886): FATAL EXCEPTION: Thread-11
02-06 20:25:18.269: E/AndroidRuntime(31886): java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
02-06 20:25:18.269: E/AndroidRuntime(31886):    at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:257)
02-06 20:25:18.269: E/AndroidRuntime(31886):    at java.util.ArrayList.get(ArrayList.java:311)
02-06 20:25:18.269: E/AndroidRuntime(31886):    at android.gesture.Instance.temporalSampler(Instance.java:91)
02-06 20:25:18.269: E/AndroidRuntime(31886):    at android.gesture.Instance.createInstance(Instance.java:76)
02-06 20:25:18.269: E/AndroidRuntime(31886):    at android.gesture.GestureStore.addGesture(GestureStore.java:158)
02-06 20:25:18.269: E/AndroidRuntime(31886):    at android.gesture.GestureLibrary.addGesture(GestureLibrary.java:68)
02-06 20:25:18.269: E/AndroidRuntime(31886):    at com.android.pack.TestActivity$B.savegesture(TestActivity.java:83)
02-06 20:25:18.269: E/AndroidRuntime(31886):    at com.android.pack.TestActivity$B.run(TestActivity.java:117)
02-06 20:25:18.269: E/AndroidRuntime(31886):    at java.lang.Thread.run(Thread.java:1019)

}

1 个答案:

答案 0 :(得分:1)

我认为你的问题在这里:

gest=dotask.batchprocess(b);

所以这段代码:

if(gest!=null)
                     {
                         System.out.println("success");
                        list.add(gest);
                     }
永远不会调用

,列表大小始终为0.