jsoup를 이용해 웹서버에서 img 태그 3개를 가지고와 각각 이미지 뷰에 뿌려줄려고합니다 .
근대 이미지를 bitmap을 이용해 이미지 뷰에 뿌려주고있는데 Thread와 bitmap 이용 하는 부분에서 계속 프로그램이 죽습니다 . 혹시나해서 textView에 jsoup를 이용해 가져온 이미지 태그를 넣어봤는데 정상적으로 출력이 됩니다 .
질문 1 ) Thread 안에서 AsyncTask를 이용한 클레스를 호출하게 되면 프로그램이 죽게되나요?
class DetailThread extends Thread {
Intent intent = getIntent();
public void run() {
String http = "http://211.226.100.190:8080/db/" + intent.getStringExtra("DetailHttp");
Document doc = null;
try {
group_name = (TextView) findViewById(R.id.group_name);
location = (TextView) findViewById(R.id.location);
content = (TextView) findViewById(R.id.content);
img_1 = (ImageView) findViewById(R.id.img_1);
img_2 = (ImageView) findViewById(R.id.img_2);
img_3 = (ImageView) findViewById(R.id.img_3);
URL url = new URL(http);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
doc = Jsoup.connect(http).get();
String group = doc.select("a").get(0).html();
String location_id = doc.select("a").get(1).html();
//String content_id=doc.select("a").get(2).html();
Elements img = doc.select("img");
String[] imgsrc = new String[img.size()];
for (int i = 0; i < img.size(); i++) {
imgsrc[i] = doc.select("img").get(i).getElementsByTag("img").attr("src");
}
OpenHttpConnection openHttpConnection = new OpenHttpConnection();
openHttpConnection.execute(img_1, "http://211.226.100.190:8080/db/" + imgsrc[0]);
openHttpConnection.execute(img_2, "http://211.226.100.190:8080/db/" + imgsrc[1]);
openHttpConnection.execute(img_3, "http://211.226.100.190:8080/db/" + imgsrc[2]);
group_name.setText(group);
location.setText(location_id);
//content.setText(content_id);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
public class OpenHttpConnection extends AsyncTask<Object, Void, Bitmap> {
private ImageView bmImage;
@Override
protected Bitmap doInBackground(Object... params) {
Bitmap mBitmap = null;
bmImage = (ImageView) params[0];
String url = (String) params[1];
InputStream in = null;
try {
in = new java.net.URL(url).openStream();
mBitmap = BitmapFactory.decodeStream(in);
in.close();
} catch (Exception ex) {
ex.printStackTrace();
}
return mBitmap;
}