마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

안드로이드 Thread 문의 [closed]

0 추천

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;
    }

 

질문을 종료한 이유: 해결완료
kane9529 (1,110 포인트) 님이 2019년 5월 21일 질문
kane9529님이 2019년 5월 21일 closed
...