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 9035199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T08:41:57+00:00 2026-06-16T08:41:57+00:00

I am using imageloader to load thumbnail images from json response, there are lots

  • 0

I am using imageloader to load thumbnail images from json response, there are lots of images obtained from json response need to parse that and place images in listview. I am getting confuse what to add in place of url[position] getting error in imgLoader.DisplayImage(url[position], loader, image); any one help me to find solution it would be a great help for me and your answer will be appreciated. thank you in advance.

following is the code and json response:

   public class AndroidLoadImageFromURLActivity extends ListActivity {

    // url to make request
   private static String desi = "http://website";

   // JSON Node names
   private static final String TAG_POSTS = "posts";
   private static final String TAG_ID = "id";
   private static final String TAG_TITLE = "title";
   private static final String TAG_DATE = "date";
   private static final String TAG_CONTENT = "content";
   private static final String TAG_AUTHOR = "author";
   private static final String TAG_NAME = "name";
   private static final String TAG_ATTACHMENTS = "attachments";
   private static final String TAG_IMAGES = "images";
   private static final String TAG_THUMBNAIL = "thumbnail";
   private static final String TAG_URL = "url";

   // contacts JSONArray
   JSONArray posts = null;


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

        // Hashmap for ListView
    ArrayList<HashMap<String, String>> contactList = new ArrayList<HashMap<String, String>>();

     // Creating JSON Parser instance
    JSONParser jParser = new JSONParser();

    // getting JSON string from URL
    JSONObject json = jParser.getJSONFromUrl(desi);

    try {
        // Getting Array of Contacts
        posts = json.getJSONArray(TAG_POSTS);

        // looping through All Contacts
        for(int i = 0; i < posts.length(); i++){
            JSONObject c = posts.getJSONObject(i);

            // Storing each json item in variable
            String id = c.getString(TAG_ID);
            String title = c.getString(TAG_TITLE);
            String date = c.getString(TAG_DATE);
            String content = c.getString(TAG_CONTENT);
            // to remove all <P> </p> and <br /> and replace with ""
             content = content.replace("<br />", "");
             content = content.replace("<p>", "");
             content = content.replace("</p>", "");

            // Author is agin  JSON Object
            JSONObject author = c.getJSONObject(TAG_AUTHOR);
            String name = author.getString(TAG_NAME);

            JSONArray attachments = json.getJSONArray(TAG_ATTACHMENTS);

            for(int j = 0; j < attachments.length(); j++){
                JSONObject d = attachments.getJSONObject(i);


            JSONObject thumbnail = d.getJSONObject(TAG_THUMBNAIL);
            String url = thumbnail.getString(TAG_URL);
            }

            // creating new HashMap
        HashMap<String, String> map = new HashMap<String, String>();



            // adding each child node to HashMap key => value
            map.put(TAG_ID, id);
            map.put(TAG_TITLE, title);
            map.put( TAG_DATE, date);
            map.put( TAG_NAME, name);
            map.put( TAG_CONTENT, content);
            // adding HashList to ArrayList
            contactList.add(map);
        }   
    } catch (JSONException e) {
        e.printStackTrace();
    }


    /**
     * Updating parsed JSON data into ListView
     * */
    ListAdapter adapter = new SimpleAdapter(this, contactList,
            R.layout.list_row,
            new String[] { TAG_TITLE, TAG_DATE, TAG_NAME, TAG_CONTENT, TAG_URL },
        new int[] { R.id.name, R.id.email,R.id.mobile, R.id.content, R.id.list_image});

    setListAdapter(adapter);

          // Loader image - will be shown before loading image
           int loader = R.drawable.loader;

             // Imageview to show
          ImageView image = (ImageView) findViewById(R.id.list_image);


    // ImageLoader class instance
     ImageLoader imgLoader = new ImageLoader(getApplicationContext());


    // whenever you want to load an image from url
    // call DisplayImage function
    // url - image url to load
    // loader - loader image, will be displayed before getting image
    // image - ImageView 
    imgLoader.DisplayImage(url[position], loader, image);
    }
     }

JSON response

{
"status": "ok",

"posts": [
    {
        "id": 2498,
        "title": "jigsaw lamp imported from thailand",
        "content": "<p>Hi. It&#8217;s a invitation to have a look at a unique lamp shade called jigsaw lamp from thailand. Available in multi attractive colours.</p>\n",
        "date": "2012-12-26 09:48:15",
         "author": {
            "name": "Tapas123456",
                        },
            "attachments": [
            {
                "description": "",
                "caption": "",
                "mime_type": "image/jpeg",
                "images": {

                    "thumbnail": {
                        "url": "http://site/wp-content/uploads/2012/12/646675-50x47.jpg",

                    }
                }
            },...............

logcat error

12-26 16:53:26.154: E/AndroidRuntime(330): FATAL EXCEPTION: main
12-26 16:53:26.154: E/AndroidRuntime(330): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.androidhive.imagefromurl/com.androidhive.imagefromurl.AndroidLoadImageFromURLActivity}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
12-26 16:53:26.154: E/AndroidRuntime(330):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
12-26 16:53:26.154: E/AndroidRuntime(330):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
12-26 16:53:26.154: E/AndroidRuntime(330):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
12-26 16:53:26.154: E/AndroidRuntime(330):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
12-26 16:53:26.154: E/AndroidRuntime(330):  at android.os.Handler.dispatchMessage(Handler.java:99)
12-26 16:53:26.154: E/AndroidRuntime(330):  at android.os.Looper.loop(Looper.java:123)
12-26 16:53:26.154: E/AndroidRuntime(330):  at android.app.ActivityThread.main(ActivityThread.java:4627)
12-26 16:53:26.154: E/AndroidRuntime(330):  at java.lang.reflect.Method.invokeNative(Native Method)
12-26 16:53:26.154: E/AndroidRuntime(330):  at java.lang.reflect.Method.invoke(Method.java:521)
12-26 16:53:26.154: E/AndroidRuntime(330):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-26 16:53:26.154: E/AndroidRuntime(330):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
12-26 16:53:26.154: E/AndroidRuntime(330):  at dalvik.system.NativeStart.main(Native Method)
12-26 16:53:26.154: E/AndroidRuntime(330): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
12-26 16:53:26.154: E/AndroidRuntime(330):  at android.app.ListActivity.onContentChanged(ListActivity.java:245)
12-26 16:53:26.154: E/AndroidRuntime(330):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:201)
12-26 16:53:26.154: E/AndroidRuntime(330):  at android.app.Activity.setContentView(Activity.java:1647)
12-26 16:53:26.154: E/AndroidRuntime(330):  at com.androidhive.imagefromurl.AndroidLoadImageFromURLActivity.onCreate(AndroidLoadImageFromURLActivity.java:44)
12-26 16:53:26.154: E/AndroidRuntime(330):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-26 16:53:26.154: E/AndroidRuntime(330):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
  • 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-16T08:41:59+00:00Added an answer on June 16, 2026 at 8:41 am

    You have declared url variable as String inside for loop

    below is your code..

    for(int j = 0; j < attachments.length(); j++)
    {
    JSONObject d = attachments.getJSONObject(i);
    JSONObject thumbnail = d.getJSONObject(TAG_THUMBNAIL);
    String url = thumbnail.getString(TAG_URL);
    }
    

    just need to declare url as url as global

    like below code.

    String url;
    for(int j = 0; j < attachments.length(); j++)
        {
        JSONObject d = attachments.getJSONObject(i);
        JSONObject thumbnail = d.getJSONObject(TAG_THUMBNAIL);
        url = thumbnail.getString(TAG_URL);
        }
    

    and use that url

    imgLoader.DisplayImage(url, loader, image);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I made a web app that loads images using jquery, ajax and json. I
I'm using this code below so randomly place images, within a container, from each
I am using imageLoader class to load image in background, after that i am
I'm using a Gallery widget adapter class to lazy load images in. The images
I am using Isotope and infinitescroll to load images into an image gallery. I
I am using TimerTask and ImageLoader class to load n image to an image
I am using the following JQuery plugin to load an image slider http://www.orionseven.com/imageloader/index.php However
I have a problem. Currently i'm using Lazyloading to load images and data into
hi guys i am in search of how to load the images from server
I am trying to load images through ajax call in jquery using This here

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.