Estoy intentando mostrar una imagen desde internet con el siguiente codigo:
try {
final ImageView prueba2 = (ImageView) view.findViewById(R.id.pruebaImagen);
URL url = new URL("http://www.expertoanimal.com/es/images/9/7/5/img_nombres_para_perros_originales_y_bonitos_5579_paso_1_600.jpg");
Bitmap bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());
prueba2.setImageBitmap(bmp);
}
catch (IOException e) {
e.printStackTrace();
}
Y me da el siguiente error:
Process: com.dedicables.videos.dedicable, PID: 24788 android.os.NetworkOnMainThreadException at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1145) at java.net.InetAddress.lookupHostByName(InetAddress.java:385) at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236) at java.net.InetAddress.getAllByName(InetAddress.java:214) at com.android.okhttp.internal.Dns$1.getAllByName(Dns.java:28) at com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:216) at com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java:122) at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:292) at com.android.okhttp.internal.http.HttpEngine.sendSocketRequest(HttpEngine.java:255) at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:206) at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:345) at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:296) at com.android.okhttp.internal.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:179) at com.dedicables.videos.dedicable.Views.Login.Login.onCreateView(Login.java:92)
Donde me marca el error en la siguiente linea:
Bitmap bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());
He intentado con varias url y me sigue dando el mismo error