gpt4 book ai didi

java - 调用 View.draw(Canvas) 方法时出现 ArrayIndexOutOfBoundException

转载 作者:行者123 更新时间:2023-11-30 02:56:20 25 4
gpt4 key购买 nike

我正在尝试在 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

有人可以帮忙吗?

最佳答案

您可以为这个异常使用 try catch block 。如下所示:

while (running) {
count++;
try {
v1.draw(new Canvas(bitmap));
} catch(ArrayIndexOutOfBoundException e){
e.printStackTrace();
}
try {
Thread.sleep(30);
} catch (InterruptedException e) {
e.printStackTrace();
throw new RuntimeException(e.getMessage());
}

System.out.println("Bitmap : [ " + count + " ] >>>>>>>> SAVED. ");
}

关于java - 调用 View.draw(Canvas) 方法时出现 ArrayIndexOutOfBoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23196316/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com