mardi 19 juillet 2016

Fetching image from url in Android

I am trying to Fetch image from Url, but i'm getting I/O exception. I really have no idea why.

 try {
        URL profilePicUrl =  new URL("http://houssup.netau.net/vivek_thumbnail.jpg");

        HttpURLConnection connection =(HttpURLConnection) profilePicUrl.openConnection();

        connection.setDoInput(true);


        connection.connect();

        InputStream inputStreamImage = connection.getInputStream();

        Bitmap profileImage = BitmapFactory.decodeStream(inputStreamImage);

        holder.profilePic.setImageBitmap(profileImage);


    } catch (MalformedURLException e) {
        Log.e("Profile Image","Error in URL");
         e.printStackTrace();
    } catch (IOException e) {
        Log.e("Profile Image","Error in IO");
        e.printStackTrace();
    }

Also i want to make point that, HttpURLconnection is throwing exception everywhere in my app. I mean in every class, I am not able to use this class.

Aucun commentaire:

Enregistrer un commentaire