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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:55:12+00:00 2026-06-09T03:55:12+00:00

I am trying to read RSS feeds from a website and display them on

  • 0

I am trying to read RSS feeds from a website and display them on my app in android. However, I am running into errors. Any ideas? i will post my logcat after the code. Please help.

package nidhin.rss;

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class RssActivity extends Activity {
/** Called when the activity is first created. */


Button ButtonStats ;
List headlines;

public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    ButtonStats = (Button) findViewById(R.id.ButtonStats);
    ButtonStats.setOnClickListener(new clicker());
    headlines = new ArrayList();

    try {


    URL url = new URL("http://feeds.pcworld.com/pcworld/latestnews");

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

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

    boolean insideItem = false;
    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(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();

        }






}

public InputStream getInputStream(URL url) {

       try {

           return url.openConnection().getInputStream();

       } catch (IOException e) {

           return null;

         }

    }



class clicker implements Button.OnClickListener
{
        public void onClick(View v)
        {                        
            if(v== ButtonStats)
            {


            }
    }

   }
}

Logcat:

08-02 21:40:02.320: E/AndroidRuntime(723): FATAL EXCEPTION: main
08-02 21:40:02.320: E/AndroidRuntime(723): java.lang.RuntimeException: Unable to start activity ComponentInfo{nidhin.rss/nidhin.rss.RssActivity}: android.os.NetworkOnMainThreadException
08-02 21:40:02.320: E/AndroidRuntime(723):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
08-02 21:40:02.320: E/AndroidRuntime(723):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
08-02 21:40:02.320: E/AndroidRuntime(723):  at android.app.ActivityThread.access$600(ActivityThread.java:123)
08-02 21:40:02.320: E/AndroidRuntime(723):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
08-02 21:40:02.320: E/AndroidRuntime(723):  at android.os.Handler.dispatchMessage(Handler.java:99)
08-02 21:40:02.320: E/AndroidRuntime(723):  at android.os.Looper.loop(Looper.java:137)
08-02 21:40:02.320: E/AndroidRuntime(723):  at android.app.ActivityThread.main(ActivityThread.java:4424)
08-02 21:40:02.320: E/AndroidRuntime(723):  at java.lang.reflect.Method.invokeNative(Native Method)
08-02 21:40:02.320: E/AndroidRuntime(723):  at java.lang.reflect.Method.invoke(Method.java:511)
08-02 21:40:02.320: E/AndroidRuntime(723):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-02 21:40:02.320: E/AndroidRuntime(723):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-02 21:40:02.320: E/AndroidRuntime(723):  at dalvik.system.NativeStart.main(Native Method)
08-02 21:40:02.320: E/AndroidRuntime(723): Caused by: android.os.NetworkOnMainThreadException
08-02 21:40:02.320: E/AndroidRuntime(723):  at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1099)
08-02 21:40:02.320: E/AndroidRuntime(723):  at java.net.InetAddress.lookupHostByName(InetAddress.java:391)
08-02 21:40:02.320: E/AndroidRuntime(723):  at java.net.InetAddress.getAllByNameImpl(InetAddress.java:242)
08-02 21:40:02.320: E/AndroidRuntime(723):  at java.net.InetAddress.getAllByName(InetAddress.java:220)
08-02 21:40:02.320: E/AndroidRuntime(723):  at libcore.net.http.HttpConnection.<init>(HttpConnection.java:71)
08-02 21:40:02.320: E/AndroidRuntime(723):  at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
08-02 21:40:02.320: E/AndroidRuntime(723):  at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:351)
08-02 21:40:02.320: E/AndroidRuntime(723):  at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:86)
08-02 21:40:02.320: E/AndroidRuntime(723):  at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
08-02 21:40:02.320: E/AndroidRuntime(723):  at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:308)
08-02 21:40:02.320: E/AndroidRuntime(723):  at libcore.net.http.HttpEngine.connect(HttpEngine.java:303)
08-02 21:40:02.320: E/AndroidRuntime(723):  at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:282)
08-02 21:40:02.320: E/AndroidRuntime(723):  at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:232)
08-02 21:40:02.320: E/AndroidRuntime(723):  at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:273)
08-02 21:40:02.320: E/AndroidRuntime(723):  at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:168)
08-02 21:40:02.320: E/AndroidRuntime(723):  at nidhin.rss.RssActivity.getInputStream(RssActivity.java:107)
08-02 21:40:02.320: E/AndroidRuntime(723):  at nidhin.rss.RssActivity.onCreate(RssActivity.java:47)
08-02 21:40:02.320: E/AndroidRuntime(723):  at android.app.Activity.performCreate(Activity.java:4465)
08-02 21:40:02.320: E/AndroidRuntime(723):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
08-02 21:40:02.320: E/AndroidRuntime(723):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
08-02 21:40:02.320: E/AndroidRuntime(723):  ... 11 more
  • 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-09T03:55:13+00:00Added an answer on June 9, 2026 at 3:55 am
    Caused by: android.os.NetworkOnMainThreadException
    

    That line in your stacktrace is telling you that you are trying to make a network call (fetch the RSS) from the main thread. Starting with API 11 (? I think) this will raise an exception.

    It is the platform designers way of trying to tell you that you really should do your network operations on the background thread.

    To fix this you’ll need to move your network calls off of the main thread. You can use either Thread / Handler, or AsyncTask to achieve this

    This tutorial by Lars Vogel is a FANTASTIC overview of both

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

Sidebar

Related Questions

I'm trying to read a XML-RSS-Feed from a website. Therefore I use a async
I want to read multiple RSS feeds using jQuery. I'm trying to write a
I am trying to read some XML code from a website, and am having
I am trying to read data from an RSS feed which has 25 items.
I'm trying to read an RSS feed from Flickr but it has some nodes
I am trying to read a handful of Rss / Atom feeds with var
How to call System.ServiceModel.Syndication.SyndicationFeed from PowerShell? I was trying to read RSS feed from
Hey trying to read stream into image control can any one help also I
I am trying to read two Rss feed urls at regular intervals and display
I'm trying to read a feed from Yahoo Pipes into a Silverlight Application. I

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.