티스토리 뷰
android.os.NetworkOnMainThreadException 안드로이드 3.0 이후부터 발생되는 오류
android.os.NetworkOnMainThreadException 안드로이드 3.0 이후부터 발생되는 오류
|
private Bitmap GetImageFromURL(String strImageURL) ;
{
Bitmap imgBitmap = null;
;
try
{
URL url = new URL(strImageURL);
URLConnection conn = url.openConnection();
conn.connect();
;
int nSize = conn.getContentLength();
BufferedInputStream bis = new BufferedInputStream(conn.getInputStream(), nSize);
imgBitmap = BitmapFactory.decodeStream(bis);
;
bis.close();
}
catch (Exception e)
{
e.printStackTrace();
}
;
return imgBitmap;
}
사용하려면
3.0이후부터 에러발생
온크리에이트나 겓뷰 밑에 아래내용 추가해주면 잘불러옴(임시방편)
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectNetwork().penaltyLog().build());
Drawable dr ; //맨위에서 선언해줌
dr에 rul이미지 저장
dr = new BitmapDrawable(GetImageFromURL("http://icon.daumcdn.net/w/icon/1312/19/152729032.png"));
'It' 카테고리의 다른 글
미국 자선재단은 기부 문화의 꽃 (0) | 2023.03.15 |
---|---|
C 문자열 문자함수 (0) | 2023.03.14 |
청소년복지의 실천방법(청소년 수련활동) (0) | 2023.03.12 |
거래의 인식과 측정 : 회계등식을 이용한 재무제표의 작성 (0) | 2023.03.12 |
원칙(原則)에 대하여(습관,패러다임, 피그말리온효과, 플라시보효과) (0) | 2023.03.11 |