Am I trying to do right? The application is compiled, but when it starts it crashes.

ImageView user_image; user_image = (ImageView) findViewById(R.id.imageView); Bitmap imageNews = getBitmapFromURL("http://img1.goodfon.ru/wallpaper/middle/0/aa/priroda-nebo-oblaka-peyzazh-5908.jpg"); user_image.setImageBitmap(imageNews); 

Class getBitmapFromURL

 public static Bitmap getBitmapFromURL(String src) { try { URL url = new URL(src); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoInput(true); connection.connect(); InputStream input = connection.getInputStream(); Log.v("123654","123654"); return BitmapFactory.decodeStream(input); } catch (IOException e) { Log.v("2345623456","2345623456"); e.printStackTrace(); return null; } } 
  • And what in LogCat displays when falling? - BArtWell
  • 2
    @batazor, in the main flow you work with the network. - Helisia
  • @bartwell prints this to gist.github.com/batazor/14c42b8c5de7112cf2a4 - batazor
  • one
    @BArtWell So, I have to perform these actions in a separate thread, for example, using AsyncTask? - batazor
  • one
    @batazor, yes, you need to bring this code to a separate thread. AsyncTask for this is quite suitable. It can be a bit simpler using new Thread (new Runnable () {}). Start (); - BArtWell

0