I'm trying to show an image from the internet with the following code:
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();
}
And I get the following 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)
Where the error marks me on the following line:
Bitmap bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());
I have tried with several url and it keeps giving me the same error