2011-01-16 8 views
2

입니다.하지만 빈 화면 만 나타나면 누구나 알 수 있습니까?아래 웹 사이트에서 이미지를 표시하려면

public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     URL url; 
     try { 
      url = new URL("http://pennapps.com/biblioteka/images/C.jpg"); 
      URLConnection conn=url.openConnection(); 
      conn.connect(); 
      InputStream is = conn.getInputStream(); 
      BufferedInputStream bis = new BufferedInputStream(is); 
      Bitmap bm = BitmapFactory.decodeStream(bis); 
      bis.close(); 
      is.close(); 
      ImageView image = new ImageView(this); 
      image.setImageBitmap(bm); 
      setContentView(image); 
     } 



     catch (Exception e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
    } 

답변

2

로그를 보지 않고 말하기는 힘들지만 일반적인 허점은 인터넷 권한을 요청하는 것을 잊어 버리는 것입니다. 또한 기본 (UI) 스레드에서 웹 요청을하지 않는 것이 좋습니다. Multithreading for Performance에는 이미지 다운로드 주제에 대해서도 다루는 훌륭한 기사가 있습니다.

+0

예, 인터넷 권한을 다시 요청하면 해당 코드가 작동합니다. 다른 실에서 그것을하는 것은 훌륭한 아이디어로 남아 있습니다. – mico

0

권한 태그를 잊어 버린 경우 코드가 작동하지 않는 것 같습니다.

관련 문제