Tengo esta clase la cual extiende de AsyncTask:
public class DownloadImage extends AsyncTask<String,Void,Bitmap> {
protected void onPostExecute(String a) {
//process message
}
@Override
protected Bitmap doInBackground(String... params) {
Bitmap myBitmap = null;
try
{
//Se define el objeto URL
URL url = new URL(params[0]);
//Se arma y configura un objeto de conexión HttpURLConnection
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
//Recibimos la respuesta de la petición en formato InputStream
InputStream input = connection.getInputStream();
System.out.println("This is the length >>>>>>>>>>>>>"+ connection.getContentLength());
//Decodificamos el InputStream a un objeto BitMap
myBitmap = BitmapFactory.decodeStream(input);
}
catch (Exception e)
{
e.printStackTrace();
}
return myBitmap;
}
}
En otra clase tengo el siguiente código el cuál usa el Bitmap
de doInBackGround()
.
DownloadImage di=new DownloadImage();
di.execute("http://192.168.150.101:8080/TDIDP/imagenes/IMG-20173175029");
final Bitmap bitmap =di.doInBackground();
Pero tengo el siguientes errores:
java.lang.ArrayIndexOutOfBoundsException: length=0; index=0 04-20 18:03:08.520 23442-23442/com.example.friky.tdidp W/System.err: at com.example.friky.tdidp.DownloadImage.doInBackground(DownloadImage.java:30) 04-20 18:03:08.520 23442-23442/com.example.friky.tdidp W/System.err: at com.example.friky.tdidp.MainMenuUsuario.cargarDatos(MainMenuUsuario.java:113)
¿Cómo puedo obtener de forma correcta el Bitmap que está en doInBackGround?