尝试将手势保存到 GestureLibrary 时出现问题
我正在从目录中的文件构建手势并尝试将它们保存在手势库中。 我无法正确执行此操作,请帮助
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你的问题就在这里:
所以这段代码:
从未被调用,并且列表大小始终为 0。
I think your problem is here :
so this code:
is never called and list size all times is 0.