Android图像下载for循环并发执行异常错误

时间:2017-05-13 16:00:23

标签: android picasso android-glide

您好我的代码存在基本问题。我想将所有图像下载为带有URL的位图。 flagUris是一个带有uris的arraylist。要下载我基本上做了一个for循环,但它给出了一个错误。我尝试捕获周围但它没有工作。我该怎么办?

private void preInit(){
    Bitmap[] myArray=new Bitmap[100];

    for(int i=0;i<flagUris.size();i++){
         myArray[i]=Glide.with(this).load(flagUris.get(i)).asBitmap().into(100, 100).get();
    }
    initializePage();
}

它表示concurrentExecutionException。我应该使用互斥锁还是有任何简单的方法来解决问题? (我尝试过毕加索和滑翔)谢谢

1 个答案:

答案 0 :(得分:0)

Bitmap[] myArray=new Bitmap[100];

可以由Glide get()启动的所有不同的异步线程同时访问它们的值。尝试使用get()时使用对象锁定和锁定数组,也许使用{ {1}},如文档herehere

所示
FutureTask

Java Synchronized Statements用于创建锁定数组的对象

相关问题