Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8432003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:00:20+00:00 2026-06-10T06:00:20+00:00

Possible Duplicate: Loading remote images I am developing an application where I have a

  • 0

Possible Duplicate:
Loading remote images

I am developing an application where I have a list in which each row has an image,

this image is loaded from a web URL.

below is my code

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ImageView
            android:id="@+id/list_row_img"
            android:layout_width="200dp"
            android:layout_height="200dp"
            />

    <TextView
            android:id="@+id/list_row_description"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            />

</LinearLayout>

and this is the activity code

@Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    ImageView img= (ImageView) findViewById(R.id.list_row_img);
    Bitmap bm = null;
    try {
         URL aURL = new URL("http://image10.bizrate-images.com/resize?sq=60&uid=2216744464");
         URLConnection conn = aURL.openConnection();
         conn.connect();
         InputStream is = conn.getInputStream();
         BufferedInputStream bis = new BufferedInputStream(is);
         bm = BitmapFactory.decodeStream(bis);
         img.setImageBitmap(bm);
         bis.close();
         is.close();

         } catch (Exception e) {
            Log.v("EXCEPTION", "Error getting bitmap", e);
         }
}

when I run i get nothing on the device. only a gray screen and no exception happens.

note that i added this permission in the manifest file

<uses-permission android:name="android.permission.INTERNET" />

can anyone help me please ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T06:00:22+00:00Added an answer on June 10, 2026 at 6:00 am

    Use below code for download image from url and display image into imageview, this will solve your problem.

    import java.io.IOException;
    import java.io.InputStream;
    import java.net.HttpURLConnection;
    import java.net.URL;
    import java.net.URLConnection;
    import android.os.Bundle;
    import android.os.StrictMode;
    import android.app.Activity;
    import android.graphics.Bitmap;
    import android.graphics.BitmapFactory;
    import android.widget.ImageView;
    
    public class MainActivity extends Activity {
    
        ImageView mImgView1;
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
                    .permitAll().build();
            StrictMode.setThreadPolicy(policy);
    
            mImgView1 = (ImageView) findViewById(R.id.mImgView1);
            String url = "https://www.morroccomethod.com/components/com_virtuemart/shop_image/category/resized/Trial_Sizes_4e4ac3b0d3491_175x175.jpg";
            BitmapFactory.Options bmOptions;
            bmOptions = new BitmapFactory.Options();
            bmOptions.inSampleSize = 1;
            Bitmap bm = loadBitmap(url, bmOptions);
            mImgView1.setImageBitmap(bm);
        }
    
        public static Bitmap loadBitmap(String URL, BitmapFactory.Options options) {
            Bitmap bitmap = null;
            InputStream in = null;
            try {
                in = OpenHttpConnection(URL);
                bitmap = BitmapFactory.decodeStream(in, null, options);
                in.close();
            } catch (IOException e1) {
            }
            return bitmap;
        }
    
        private static InputStream OpenHttpConnection(String strURL)
                throws IOException {
            InputStream inputStream = null;
            URL url = new URL(strURL);
            URLConnection conn = url.openConnection();
    
            try {
                HttpURLConnection httpConn = (HttpURLConnection) conn;
                httpConn.setRequestMethod("GET");
                httpConn.connect();
    
                if (httpConn.getResponseCode() == HttpURLConnection.HTTP_OK) {
                    inputStream = httpConn.getInputStream();
                }
            } catch (Exception ex) {
            }
            return inputStream;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: C/C++ Image Loading I need a C\C++ cross-platform library for loading/displaying images(jpg,gif,png,tga).
Possible Duplicate: Loading remote images How to put a picture from the Internet in
Possible Duplicate: How can I add loading text/image to images that are still loading
Possible Duplicate: Error loading Active Record gem with sinatra app using RVM I have
Possible Duplicate: Can I use predefined namespaces when loading an XDocument? I have following
Possible Duplicate: jQuery or JavaScript: Determine when image finished loading The problem is known,
Possible Duplicate: Jquery IE6 hover problems, keeps loading background image. Hello I am trying
Possible Duplicate: Loading model using Jeff Lamarches script Guys this might sound very newbie
Possible Duplicate: vertical alignment of image inside a div OK, this what I'm trying
Possible Duplicate: Change the URL in the browser without loading the new page using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.