URL로 이미지 불러와서 imagview 에 보여주는 걸 하고 있습니다.
AsyncTask 없이는 잘되었는데요. 다이얼로그 하려고 AsyncTask 로직 넣고 하니까
이미지는 안뜨고 false 가 나오고 로딩되다가 강제종료 창 뜹니다.ㅠㅠ
=======================================
package com.helloworld.com;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import android.app.Activity;
import android.app.ProgressDialog;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.Log;
import android.widget.ImageView;
public class HelloActivity extends Activity{
public void onCreate(Bundle savedInstanceState) {
Log.w("DevLog", "onCreate");
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MyAsyncTask task = new MyAsyncTask();
task.execute();
}
class MyAsyncTask extends AsyncTask <Void, Void, Void> {
private ProgressDialog dialog;
@Override
protected Void doInBackground(Void... params) {
String Resized = "http://www.gomonews.com/wp-content/uploads/2009/07/android-logo.jpg";
ImageView iv = (ImageView)findViewById(R.id.ImageV);
try {
URL aURL = new URL(Resized);
URLConnection conn = aURL.openConnection();
conn.connect();
InputStream is = conn.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
Bitmap bm = BitmapFactory.decodeStream(bis);
bis.close();
is.close();
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
int newHeight = (int)((float)dm.widthPixels / (float)bm.getWidth() * (float)bm.getHeight());
Bitmap bmresized = Bitmap.createScaledBitmap(bm, dm.widthPixels, newHeight, true);
iv.setImageBitmap(bmresized);
}
catch (IOException e) {
Log.e("DevLog", "Remtoe Image Exception", e);
e.printStackTrace();
}
dialog.dismiss();
return null;
}
@Override
protected void onPreExecute() {
ProgressDialog.show(HelloActivity.this,"","loading",true);
super.onPreExecute();
}
@Override
protected void onPostExecute(Void result) {
Log.w("DevLog", "onPostExecute");
dialog.dismiss();
super.onPostExecute(result);
}
}
}
===============================================
12-24 03:26:47.615: WARN/dalvikvm(4523): threadid=13: thread exiting with uncaught exception (group=0x4001d1c8)
12-24 03:26:47.615: ERROR/AndroidRuntime(4523): Uncaught handler: thread AsyncTask #1 exiting due to uncaught exception
12-24 03:26:47.623: ERROR/AndroidRuntime(4523): java.lang.RuntimeException: An error occured while executing doInBackground()
12-24 03:26:47.623: ERROR/AndroidRuntime(4523): at android.os.AsyncTask$3.done(AsyncTask.java:200)
12-24 03:26:47.623: ERROR/AndroidRuntime(4523): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
12-24 03:26:47.623: ERROR/AndroidRuntime(4523): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
12-24 03:26:47.623: ERROR/AndroidRuntime(4523): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
12-24 03:26:47.623: ERROR/AndroidRuntime(4523): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
12-24 03:26:47.623: ERROR/AndroidRuntime(4523): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
12-24 03:26:47.623: ERROR/AndroidRuntime(4523): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
12-24 03:26:47.623: ERROR/AndroidRuntime(4523): at java.lang.Thread.run(Thread.java:1096)
12-24 03:26:47.623: ERROR/AndroidRuntime(4523): Caused by: java.lang.NullPointerException
12-24 03:26:47.623: ERROR/AndroidRuntime(4523): at com.helloworld.com.HelloActivity$MyAsyncTask.doInBackground(HelloActivity.java:55)
12-24 03:26:47.623: ERROR/AndroidRuntime(4523): at com.helloworld.com.HelloActivity$MyAsyncTask.doInBackground(HelloActivity.java:1)
12-24 03:26:47.623: ERROR/AndroidRuntime(4523): at android.os.AsyncTask$2.call(AsyncTask.java:185)
12-24 03:26:47.623: ERROR/AndroidRuntime(4523): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
12-24 03:26:47.623: ERROR/AndroidRuntime(4523): ... 4 more




만드신 bitmap을 return시켜서 onPostExcute에서 view에 넣어주시면 되겠네요