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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:40:56+00:00 2026-06-18T00:40:56+00:00

I am creating an RSS reader application for android 4.0+. I have put the

  • 0

I am creating an RSS reader application for android 4.0+. I have put the reader code in AsyncTask because of the NetworkOnMainThreadException. The code almost works fine, however one line has an error. This is my code:

Java code:

   private class PostTask extends AsyncTask<String, Integer, String> {
   @Override
   protected void onPreExecute() {
   super.onPreExecute();
   }

   @Override
   protected String doInBackground(String... params) {
  String url=params[0];
   headlines = new ArrayList();
   links = new ArrayList();

   //Download and parse xml feed
   headlines = new ArrayList();
   links = new ArrayList();

   try {
    URL url1 = new URL("http://feeds.pcworld.com/pcworld/latestnews");

    XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
    factory.setNamespaceAware(false);
    XmlPullParser xpp = factory.newPullParser();

           // We will get the XML from an input stream
    xpp.setInput(getInputStream(url1), "UTF_8");

           /* We will parse the XML content looking for the "<title>" tag which appears inside the "<item>" tag.
            * However, we should take in consideration that the rss feed name also is enclosed in a "<title>" tag.
            * As we know, every feed begins with these lines: "<channel><title>Feed_Name</title>...."
            * so we should skip the "<title>" tag which is a child of "<channel>" tag,
            * and take in consideration only "<title>" tag which is a child of "<item>"
            *
            * In order to achieve this, we will make use of a boolean variable.
            */
    boolean insideItem = false;

           // Returns the type of current event: START_TAG, END_TAG, etc..
    int eventType = xpp.getEventType();
    while (eventType != XmlPullParser.END_DOCUMENT) {
        if (eventType == XmlPullParser.START_TAG) {

            if (xpp.getName().equalsIgnoreCase("item")) {
                insideItem = true;
            } else if (xpp.getName().equalsIgnoreCase("title")) {
                if (insideItem)
                    headlines.add(xpp.nextText()); //extract the headline
            } else if (xpp.getName().equalsIgnoreCase("link")) {
                if (insideItem)
                    links.add(xpp.nextText()); //extract the link of article
            }
        }else if(eventType==XmlPullParser.END_TAG && xpp.getName().equalsIgnoreCase("item")){
            insideItem=false;
        }

        eventType = xpp.next(); //move to next element
    }

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

  return "Feed parsed!";
   }

   @Override
   protected void onProgressUpdate(Integer... values) {
  super.onProgressUpdate(values);
   }

   @Override
   protected void onPostExecute(String result) {
  super.onPostExecute(result);
   // Binding data
  ArrayAdapter adapter = new ArrayAdapter(this,
          android.R.layout.simple_list_item_1, headlines);
  setListAdapter(adapter);

   }
   }

in this code snippet i get an error:

@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
// Binding data
ArrayAdapter adapter = new ArrayAdapter(this,
          android.R.layout.simple_list_item_1, headlines);
setListAdapter(adapter);
}

Error: The constructor ArrayAdapter(MainActivity.PostTask, int, List) is undefined.

Logcat:

01-26 20:55:53.811: E/AndroidRuntime(1830): FATAL EXCEPTION: AsyncTask #1
01-26 20:55:53.811: E/AndroidRuntime(1830): java.lang.RuntimeException: An error occured while executing doInBackground()
01-26 20:55:53.811: E/AndroidRuntime(1830):     at android.os.AsyncTask$3.done(AsyncTask.java:278)
01-26 20:55:53.811: E/AndroidRuntime(1830):     at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
01-26 20:55:53.811: E/AndroidRuntime(1830):     at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
01-26 20:55:53.811: E/AndroidRuntime(1830):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
01-26 20:55:53.811: E/AndroidRuntime(1830):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
01-26 20:55:53.811: E/AndroidRuntime(1830):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
01-26 20:55:53.811: E/AndroidRuntime(1830):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
01-26 20:55:53.811: E/AndroidRuntime(1830):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
01-26 20:55:53.811: E/AndroidRuntime(1830):     at java.lang.Thread.run(Thread.java:856)
01-26 20:55:53.811: E/AndroidRuntime(1830): Caused by: java.lang.IllegalArgumentException
01-26 20:55:53.811: E/AndroidRuntime(1830):     at org.kxml2.io.KXmlParser.setInput(KXmlParser.java:1615)
01-26 20:55:53.811: E/AndroidRuntime(1830):     at com.mysoftware.mysoftwareos.mobile.MainActivity$PostTask.doInBackground(MainActivity.java:343)
01-26 20:55:53.811: E/AndroidRuntime(1830):     at com.mysoftware.mysoftwareos.mobile.MainActivity$PostTask.doInBackground(MainActivity.java:1)
01-26 20:55:53.811: E/AndroidRuntime(1830):     at android.os.AsyncTask$2.call(AsyncTask.java:264)
01-26 20:55:53.811: E/AndroidRuntime(1830):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
01-26 20:55:53.811: E/AndroidRuntime(1830):     ... 5 more

Could anyone please look into my problem and come up with a solution? Or tell me if i should do anything different? Thanks a lot!

  • 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-18T00:40:57+00:00Added an answer on June 18, 2026 at 12:40 am

    use Activity Context instead of AsyncTask to Create ArrayAdapter inside onPostExecute method as :

    ArrayAdapter<String> adapter = 
                          new ArrayAdapter<String>(Your_Current_Activity.this,
                          android.R.layout.simple_list_item_1, headlines);
      setListAdapter(adapter);
    

    EDIT :
    after log posted also change

    xpp.setInput(getInputStream(url1), "UTF_8");
    

    to

    xpp.setInput(url1.openConnection().getInputStream(), "UTF_8");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a small RSS Reader application. The code I am using to
i am creating rss reader application with php.it is basicly getting rss url's from
I'm creating an Android application that requires the following: Data from RSS feed gets
I just downloaded the code from http://cocoadevblog.com/iphone-tutorial-creating-a-rss-feed-reader to see how to implement rss feeder
I'm creating RSS reader application. I need to get any linked rss old items.
Im creating an RSS reader app...but I have noticed that UIWebView renders the RSS
I creating a rss reader for a site from Denmark, they have some thing
I am creating a simple RSS reader which displays headlines in ListView, downloading it
I'm creating my own RSS Reader, and to see which RSS items were already
I am creating a simple RSS application and I am not that good in

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.