下面是我尝试将图像下载到Android应用程序内的活动。我的应用程序崩溃在行img1.setImageDrawable(d);我有一个LinearLayout里面的RelativeLayout ..不知道为什么这会一直崩溃..我需要总共四个图像下载到活动,我是否正确设置xml以获得四个图像或我需要对于个人ImageView的?任何建议/想法/提示,非常感谢。从Android中的线程下载图像
Thread t = new Thread(){
@Override
public void run(){
int i = imgarr.length;
int j = 0;
while(j<i){
try {
InputStream is = (InputStream) new URL(imgarr[j]).getContent();
Drawable d = Drawable.createFromStream(is,"pic");
img1.setImageResource(d);
j++;
} catch (MalformedURLException e) {}
catch (IOException e) {}
}
}//end run
};
t.start();
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dip"
android:layout_below="@id/adbody"
>
<ImageView android:id="@+id/image1" android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:paddingTop="15dip"/>
</LinearLayout>
logcat关于崩溃的说法是什么?什么是错误? –
这些文件是否已经存储在本地?基本上,imgarr充满了文件路径? –
@ B.Young imgarr充满了IMG的网址... – Andrew