안드로이드 개발 질문/답변
(글 수 40,700)
안녕하세요.
제가 Web의 이미지르 보여주기 위해서 아래와 같은 함수를 사용하였습니다.
public void getImageURL() {
final Intent intent = getIntent();
VISIT_IMAGEURI = intent.getStringExtra(GET_URL);
final ImageView view =(ImageView) findViewById(R.id.Visit_Image);
view.setImageDrawable(draw);
}
public Drawable loadDrawable(String urlStr) {
Drawable drawable = null;
final String LOG_TAG = "GeaphicsSample";
try {
URL url = new URL(urlStr);
InputStream is = url.openStream();
drawable = Drawable.createFromStream(is, "none");
}
catch(Exception e){
Log.e(LOG_TAG,"error,in loadDrawable \n"+ e.toString());
}
return drawable;
}
URL string 을 Intent로 받아와서 Imageview에 Drawble 로 뿌려주는 형식인데요.
문제는 입력한 URL이 잘못 되었을 경우 그 예외 처리를 해주어야 하는 것입니다.
loadDrawable 함수에서 catch 문에서 잡을 수 있을 줄 알았는데 그곳으로 들어오지는 않더라구요,
URL 스트링이 잘못되었을 경우 이것을 catch 할수 있는 방법이 있나요?
고수님들의 도움 부탁 드립니다.
제가 Web의 이미지르 보여주기 위해서 아래와 같은 함수를 사용하였습니다.
public void getImageURL() {
final Intent intent = getIntent();
VISIT_IMAGEURI = intent.getStringExtra(GET_URL);
final ImageView view =(ImageView) findViewById(R.id.Visit_Image);
view.setImageDrawable(draw);
}
public Drawable loadDrawable(String urlStr) {
Drawable drawable = null;
final String LOG_TAG = "GeaphicsSample";
try {
URL url = new URL(urlStr);
InputStream is = url.openStream();
drawable = Drawable.createFromStream(is, "none");
}
catch(Exception e){
Log.e(LOG_TAG,"error,in loadDrawable \n"+ e.toString());
}
return drawable;
}
URL string 을 Intent로 받아와서 Imageview에 Drawble 로 뿌려주는 형식인데요.
문제는 입력한 URL이 잘못 되었을 경우 그 예외 처리를 해주어야 하는 것입니다.
loadDrawable 함수에서 catch 문에서 잡을 수 있을 줄 알았는데 그곳으로 들어오지는 않더라구요,
URL 스트링이 잘못되었을 경우 이것을 catch 할수 있는 방법이 있나요?
고수님들의 도움 부탁 드립니다.
if ( d == null ) {
넌 예외
} else ...