Hi, 

I have a simple java file that fetches a RSS Feed from a webpage and 
displays the title tag on the console in eclipse.  It works fine.
But now I am trying to use the same class in my Android application and 
it's not working. Below is my .java file that's fetching the RSS feed XML:

import java.io.IOException;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.DOMException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;


public class RSSTest {
    public static String[] titles;
    
    public static void writeFeed(){
        try {
            DocumentBuilderFactory factory = 
DocumentBuilderFactory.newInstance();
            DocumentBuilder builder = factory.newDocumentBuilder();
            Document doc = 
builder.parse("http://fbrss.com/f/daea930ed6d29773bc07b4e6e74b5c70_7LtWgbABJGOOKCW4pWrI.xml";);
            
            NodeList list = doc.getElementsByTagName("title");
            titles = new String[list.getLength()];
            for(int i = 1; i<titles.length; i++) {
                Element item = (Element) list.item(i);
                if(!item.getFirstChild().getNodeValue().contains("Photo"))
                    titles[i] = item.getFirstChild().getNodeValue();
            }
        } catch (DOMException e) {
                       e.printStackTrace();
        } catch (ParserConfigurationException e) {
                      e.printStackTrace();
        } catch (SAXException e) {
                      e.printStackTrace();
        } catch (IOException e) {
                      e.printStackTrace();
        }
    }
    
   }

The above file runs fine as a Java application.  But I am making an android 
app and trying to use the strings fetched in titles[].  I am simply trying 
to display the string from let's say titles[1] on the display on a 
TextView.  Below is my code for Android app:


package com.kaushal.JustRss;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class JustRSSActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       RSS.writeFeed();
       String s = RSS.titles[2];
        TextView tv = (TextView)findViewById(R.id.textView1);
        tv.setText(s);
        
    }
}

When it goes to RSS.writeFeed() line, it goes in to IO Exception.

Any help would be appreciated.


-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to