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

发布于 2025-01-02 12:12:51 字数 3137 浏览 0 评论 0原文

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

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)

}

I am building gestures from files in a directory and trying to save them in a gesturelibary.
I am unable to do so correctly please help

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();

}
can anyone say where is the error from my LogCat I cannot understand it.

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)

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

泼猴你往哪里跑 2025-01-09 12:12:51

我认为你的问题就在这里:

gest=dotask.batchprocess(b);

所以这段代码:

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

从未被调用,并且列表大小始终为 0。

I think your problem is here :

gest=dotask.batchprocess(b);

so this code:

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

is never called and list size all times is 0.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文