我正在尝试从asynctask()中的线性布局创建位图。请在此处找到代码:
while (running) {
count++;
v1.draw(new Canvas(bitmap));//I am getting exception here
//sleep thread to give some lag
try {
Thread.sleep(30);
} catch (InterruptedException e) {
e.printStackTrace();
throw new RuntimeException(e.getMessage());
}
System.out.println("Bitmap : [ " + count + " ] >>>>>>>> SAVED. ");
}
我收到的错误是:
04-21 16:29:46.768: E/AndroidRuntime(20850): Caused by: java.lang.IndexOutOfBoundsException: 1, 1
04-21 16:29:46.768: E/AndroidRuntime(20850): at android.text.PackedIntVector.getValue(PackedIntVector.java:70)
04-21 16:29:46.768: E/AndroidRuntime(20850): at android.text.DynamicLayout.getLineTop(DynamicLayout.java:592)
04-21 16:29:46.768: E/AndroidRuntime(20850): at android.text.Layout.getLineForVertical(Layout.java:1015)
04-21 16:29:46.768: E/AndroidRuntime(20850): at android.text.Layout.getLineRangeForDraw(Layout.java:460)
04-21 16:29:46.768: E/AndroidRuntime(20850): at android.text.Layout.draw(Layout.java:198)
04-21 16:29:46.768: E/AndroidRuntime(20850): at android.widget.Editor.onDraw(Editor.java:1306)
04-21 16:29:46.768: E/AndroidRuntime(20850): at android.widget.TextView.onDraw(TextView.java:5163)
04-21 16:29:46.768: E/AndroidRuntime(20850): at android.view.View.draw(View.java:14465)
04-21 16:29:46.768: E/AndroidRuntime(20850): at android.view.View.draw(View.java:14350)
04-21 16:29:46.768: E/AndroidRuntime(20850): at android.view.ViewGroup.drawChild(ViewGroup.java:3103)
04-21 16:29:46.768: E/AndroidRuntime(20850): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2940)
04-21 16:29:46.768: E/AndroidRuntime(20850): at android.view.View.draw(View.java:14468)
04-21 16:29:46.768: E/AndroidRuntime(20850): at com.sample.ScreenShotTask.takeScreenshots(ScreenShotTask.java:75)
04-21 16:29:46.768: E/AndroidRuntime(20850): at com.sample.ScreenShotTask.doInBackground(ScreenShotTask.java:35)
04-21 16:29:46.768: E/AndroidRuntime(20850): at com.sample.ScreenShotTask.doInBackground(ScreenShotTask.java:1)
04-21 16:29:46.768: E/AndroidRuntime(20850): at android.os.AsyncTask$2.call(AsyncTask.java:288)
04-21 16:29:46.768: E/AndroidRuntime(20850): at java.util.concurrent.FutureTask.run(FutureTask.java:237)
04-21 16:29:46.768: E/AndroidRuntime(20850): ... 4 more
有人可以帮忙吗?
答案 0 :(得分:1)
您可以将try catch块用于此异常。如下所示:
while (running) {
count++;
try{
v1.draw(new Canvas(bitmap));//I am getting exception here
//sleep thread to give some lag
} catch(ArrayIndexOutOfBoundException e){
e.printStackTrace();
//do handling action.. or skip as per ur requirement.
}
try {
Thread.sleep(30);
} catch (InterruptedException e) {
e.printStackTrace();
throw new RuntimeException(e.getMessage());
}
System.out.println("Bitmap : [ " + count + " ] >>>>>>>> SAVED. ");
}