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

  • SEARCH
  • Home
  • 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 9267809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:38:38+00:00 2026-06-18T14:38:38+00:00

I am trying to parse the xml file and trying to load images and

  • 0

I am trying to parse the xml file and trying to load images and textviews and display it in a list view but whenever i try to load images in getView method in force closes the application even if try to scroll fast it also does the same. Iam tired of doing it in thread and asynctask for 5hours.please help if someone can solve it. Here are my two class files.

class NewsRowAdapter

public class NewsRowAdapter extends ArrayAdapter<Item> 
{
    LoadingImage loadingImage;

    Bitmap bitmap = null;

    private Activity activity;

    private List<Item> items;

    private Item objBean;

    private int row;

    public NewsRowAdapter(Activity act, int resource, List<Item> arrayList) 
    {

        super(act, resource, arrayList);

        this.activity = act;

        this.row = resource;

        this.items = arrayList;


    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent)
    {
        View view = convertView;

        final ViewHolder holder;

        if (view == null) 
        {

            LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

            view = inflater.inflate(row, null);

            holder = new ViewHolder();

            view.setTag(holder);

        } else 
        {
            holder = (ViewHolder) view.getTag();
        }

        if ((items == null) || ((position + 1) > items.size()))

            return view;

        objBean = items.get(position);

        holder.tvTitle = (TextView) view.findViewById(R.id.tvtitle);

        holder.tvDesc = (TextView) view.findViewById(R.id.tvdesc);

        holder.tvDate = (TextView) view.findViewById(R.id.tvdate);

        holder.imgView = (ImageView) view.findViewById(R.id.image);

        holder.pbar = (ProgressBar) view.findViewById(R.id.pbar);

        if (holder.tvTitle != null && null != objBean.getTitle() && objBean.getTitle().trim().length() > 0) 
        {
            holder.tvTitle.setText(Html.fromHtml(objBean.getTitle()));
        }
        if (holder.tvDesc != null && null != objBean.getDesc() && objBean.getDesc().trim().length() > 0)
        {
            holder.tvDesc.setText(Html.fromHtml(objBean.getDesc()));
        }
        if (holder.tvDate != null && null != objBean.getPubdate() && objBean.getPubdate().trim().length() > 0)
        {
            holder.tvDate.setText(Html.fromHtml(objBean.getPubdate()));
        }
        if (holder.imgView != null) 
        {
            if (null != objBean.getLink() && objBean.getLink().trim().length() > 0) 
            {
                final ProgressBar pbar = holder.pbar;

                pbar.setVisibility(View.INVISIBLE);


                //---------CHANGES MADE FOR LOADING IMAGE----------//

                Log.d("IMAGE NULL----------", objBean.getLink());


                //loadBitmap(objBean.getLink());

                /*new Thread() 
                {
                    public void run() 
                    {*/
                        try 
                        {
                            URL linkurl = new URL(objBean.getLink());

                            bitmap = BitmapFactory.decodeStream(linkurl.openConnection().getInputStream());

                            holder.imgView.setImageBitmap(bitmap);

                        } catch (MalformedURLException e) 
                        {
                            e.printStackTrace();

                        } catch (IOException e) 
                        {
                            e.printStackTrace();
                        }
                    /*}
                }.start();*/



            } else 
            {
                holder.imgView.setImageResource(R.drawable.ic_launcher);
            }
        }

        return view;
    }


    //------LOADING IMAGE FROM URL------//


    public static Bitmap loadBitmap(String url) 
    {
        Bitmap bitmap = null;

        final AndroidHttpClient client = AndroidHttpClient.newInstance("Android");
        final HttpGet getRequest = new HttpGet(url);

        try 
        {
            HttpResponse response = client.execute(getRequest);
            final int statusCode = response.getStatusLine().getStatusCode();
            if (statusCode != HttpStatus.SC_OK) 
            { 
                Log.d("ImageDownloader", "Error " + statusCode + " while retrieving bitmap from " + url); 
                return null;
            }

            final HttpEntity entity = response.getEntity();
            if (entity != null)
            {
                InputStream inputStream = null;
                try 
                {
                    inputStream = entity.getContent(); 

                    bitmap = BitmapFactory.decodeStream(inputStream);



                } finally
                {
                    if (inputStream != null)
                    {
                        inputStream.close();  
                    }
                    entity.consumeContent();
                }
            }
        } catch (Exception e) 
        {
            // Could provide a more explicit error message for IOException or IllegalStateException
            getRequest.abort();

            Log.d("Error while retrieving bitmap from " + url, e.toString());
        } finally 
        {
            if (client != null)
            {
                client.close();
            }
        }


        return bitmap;
    }




    public class ViewHolder
    {

        public TextView tvTitle, tvDesc, tvDate;
        private ImageView imgView;
        private ProgressBar pbar;

    }

}

and the main class is :

class MainActivity

public class MainActivity extends Activity implements OnItemClickListener
{
    private static final String rssFeed = /*"https://www.dropbox.com/s/t4o5wo6gdcnhgj8/imagelistview.xml?dl=1"*/"http://78.46.34.27/kapapps/newparsedtransaction.xml";

    List<Item> arrayOfList;
    ListView listView;

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

        listView = (ListView) findViewById(R.id.listview);
        listView.setOnItemClickListener(this);

        if (Utils.isNetworkAvailable(NewTransactionActivity.this)) 
        {
            new MyTask().execute(rssFeed);
        } else 
        {
            showToast("No Network Connection!!!");
        }

    }

    // My AsyncTask start...

    class MyTask extends AsyncTask<String, Void, Void> 
    {

        ProgressDialog pDialog;

        @Override
        protected void onPreExecute() 
        {
            super.onPreExecute();

            pDialog = new ProgressDialog(NewTransactionActivity.this);
            pDialog.setTitle("Latest Transaction");
            pDialog.setMessage("Loading... Please wait");
            pDialog.show();

        }

        @Override
        protected Void doInBackground(String... params) 
        {
            arrayOfList = new NamesParser().getData(params[0]);
            return null;
        }

        @Override
        protected void onPostExecute(Void result) 
        {
            super.onPostExecute(result);



            if (null == arrayOfList || arrayOfList.size() == 0) 
            {

                showToast("No data found from web!!!");

                NewTransactionActivity.this.finish();

            } else 
            {

                // check data...
                /*
                 * for (int i = 0; i < arrayOfList.size(); i++) 
                 * { 
                 *  Item item = arrayOfList.get(i); System.out.println(item.getId());
                 *  System.out.println(item.getTitle());
                 *  System.out.println(item.getDesc());
                 *  System.out.println(item.getPubdate());
                 *  System.out.println(item.getLink()); 
                 * }
                 */
                for(int i = 0 ; i < arrayOfList.size() ; i++)
                {   
                    Item item = arrayOfList.get(i);
                    Log.d("ID NEWTRANSACTION ACTIVITY ------>" , item.getId());
                    Log.d("TITLE NEWTRANSACTION ACTIVITY ------>" , item.getTitle());
                    Log.d("DESC NEWTRANSACTION ACTIVITY ------>", item.getDesc());
                    Log.d("LINK NEWTRANSACTION ACTIVITY ------>", item.getLink());
                }

                setAdapterToListview();


            }


            if (null != pDialog && pDialog.isShowing()) 
            {
                pDialog.dismiss();
            }




        }
    }

    @Override
    public void onItemClick(AdapterView<?> parent , View view , int position ,  long id) 
    {
        Item item = arrayOfList.get(position);
        Intent intent = new Intent(NewTransactionActivity.this, DetailActivity.class);
        intent.putExtra("url", item.getLink());
        intent.putExtra("title", item.getTitle());
        intent.putExtra("desc", item.getDesc());


        Log.d("IMAGE_URL------>" , item.getLink());
        startActivity(intent);
    }

    public void setAdapterToListview() 
    {
        NewsRowAdapter objAdapter = new NewsRowAdapter(NewTransactionActivity.this , R.layout.row, arrayOfList);
        listView.setAdapter(objAdapter);
    }

    public void showToast(String msg) 
    {

    }


}
  • 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-18T14:38:40+00:00Added an answer on June 18, 2026 at 2:38 pm

    Do Image retrieving logic in another thread.It is taking too much time to load Images that’s why you are getting ANR.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to parse Xml file using PHP but whenever i runs the
I am trying to parse an XML file with python using lxml, but get
I'm trying to parse an XML file using PHP, but I get an error
I'm trying to parse a XML file, but when loading it simpleXML prints the
I am trying to parse an xml file and load Flex modules dynamically in
So I am trying to parse an XML file and display first 150 words
Hi there I'm trying to parse an XML file into a list of contacts,
I'm trying to parse an xml file by starting with simplexml_load_file to load the
I am trying to parse specific XML file which is located in sub directories
I'm trying parse the follow XML file: <root>Root <pai>Pai_1 <filho>Pai1,Filho1</filho> <filho>Pai1,Filho2</filho> </pai> <pai>Pai_2 <filho>Pai2,Filho1</filho>

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.