0

I am newbie to android, I am trying to parse xml data from http://www.astrology.com/horoscopes/daily-horoscope.rss, I grab the code from How can I parse xml from url in android? here, I used sherLock library, I also set internet permissions in manifest, but still unable to grab it, here is the same code except a little modification,

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    /* Create a new layout to display the view */
    LinearLayout layout = new LinearLayout(this);
    layout.setOrientation(1);

    /* Create a new textview array to display the results */
    TextView name[];
    //TextView website[];
    //TextView category[];

    try {

        URL url = new URL("http://www.astrology.com/horoscopes/daily-horoscope.rss");
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = dbf.newDocumentBuilder();
        Document doc = db.parse(new InputSource(url.openStream()));
        doc.getDocumentElement().normalize();

        NodeList nodeList = doc.getElementsByTagName("item");

        /** Assign textview array lenght by arraylist size */
        name = new TextView[nodeList.getLength()];
       // website = new TextView[nodeList.getLength()];
        //category = new TextView[nodeList.getLength()];

        for (int i = 0; i < nodeList.getLength(); i++) {

            Node node = nodeList.item(i);

            name[i] = new TextView(this);
            //website[i] = new TextView(this);
            //category[i] = new TextView(this);

            Element fstElmnt = (Element) node;
            NodeList nameList = ((Document) fstElmnt).getElementsByTagName("title");
            Element nameElement = (Element) nameList.item(0);
            nameList = ((Node) nameElement).getChildNodes();
            name[i].setText("Name = " + ((Node) nameList.item(0)).getNodeValue());

            //category[i].setText("Website Category = " + ((org.w3c.dom.Element) websiteElement).getAttribute("category"));

            layout.addView(name[i]);
            //layout.addView(website[i]);
            //layout.addView(category[i]);
        }
    } catch (Exception e) {
        System.out.println("XML Pasing Excpetion = " + e);
    }

    /** Set the layout view to display */
    setContentView(layout);

}

Remember I am extending my MainActivity class from SherlockActivity, when I execute the code, only action bar appears!

Community
  • 1
  • 1
Irfan Ahmed
  • 9,136
  • 8
  • 33
  • 54
  • I'm not sure if this is entirely the problem but make sure you setLayoutParams on your `TextView` (and all your created Views) http://stackoverflow.com/a/2397869/833647 – Ken Wolf Jul 09 '13 at 14:04
  • Did you try debugging and stepping through your code to verify you are getting results put into your TextViews ? – dymmeh Jul 09 '13 at 14:07
  • 07-09 20:18:18.567: I/dalvikvm(281): Could not find method android.widget.LinearLayout.setTranslationX, referenced from method com.actionbarsherlock.internal.nineoldandroids.widget.NineLinearLayout.setTranslationX – Irfan Ahmed Jul 09 '13 at 14:20

0 Answers0