Bitmap bitmap = BitmapFactory.decodeStream(result);
HERE IN LOG I AM GETTING
03-05 06:47:36.639: E/bitmap(931): android.graphics.Bitmap@417d5948
BUT THEN EXCEPTION COMES OF NULL POINTER EXCEPTION
public class DetailsActivity extends Activity {
private ImageView image;
//ASYNCTASK
class DownloadImageTask extends AsyncTask<Void, Void, InputStream> {
private ProgressDialog dialog;
@Override
protected void onPreExecute() {
super.onPreExecute();
dialog = new ProgressDialog(DetailsActivity.this);
dialog.setTitle("Please wait");
dialog.setMessage("Please wait while the application is downloading the image");
dialog.setCancelable(false);
dialog.show();
}
@Override
protected InputStream doInBackground(Void... params) {
try {
Thread.sleep(5000);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
url FROM WHERE WE HAVE TO FETCH IMAGE
String stringURL = "http://theopentutorials.com/totwp331/wp-content/uploads/totlogo.png";
try {
Log.e("URL TEST",""+stringURL);
stringURL=stringURL.replaceAll(" ", "%20");
URL url = new URL(stringURL);
Log.e("URL TEST",""+url);
//stringURL=stringURL.replaceAll(" ", "%20");
URLConnection connection = url.openConnection();
InputStream stream = connection.getInputStream();
Log.e("TESTING","TESTING"+ stream);
return stream;
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(InputStream result) {
super.onPostExecute(result);
//Bitmap bi = BitmapFactory.
try{Bitmap bitmap = BitmapFactory.decodeStream(result);
Log.e("bitmap",""+bitmap);
ERROR AT THIS LINE==>image.setImageBitmap(bitmap);
//Log.e("final"," " + image.setImageBitmap(bitmap));
}catch(Exception e){
Log.e(" YNull" , ""+ e);//NULL POINTER EXCEPTION
}
dialog.cancel();
}
}
private void asyncDownload() {
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
.detectNetwork().build());
DownloadImageTask task = new DownloadImageTask();
task.execute();
}
///////////////////////////////////////////////////////////////////////////////
Async Dowloader
/////////////////////////////////////////////////////////////////////////////
ONCREATE METHORD
IMAGE IS NOT GETTING FETCHED
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
image = (ImageView)findViewById(R.id.imageView2);
ActionBar actionBar = getActionBar();
actionBar.hide();
setContentView(R.layout.activity_details);
asyncDownload();
}