-1

I am trying to write a simple RSS Reader. I think i done but I get exception with "null" message. JavaDoc said that it is possible to get this value so it's nothing strange. But how could I find out what is wrong with my code? part 1 part 2 and main:

public static void main(String[] args) throws MalformedURLException {
    URL url = new URL("http://facet.wp.pl/rss.xml");
    Feed feed = new Feed();
    RSSParser parser = new RSSParser(url);
    parser.RSSFeed();

    for(String wejscia : feed.entries){
        System.out.println(wejscia);
    }
}

@EDIT The exception is at RSSParser.RSSFeed(RSSParser.java:28) and i have already know that it's a NullPointerException

  • 4
    So, what is the exception. Where is it thrown? What's the stack trace? – JB Nizet Mar 20 '16 at 18:02
  • I managed to pull out that it is java.lang.NullPointerException. Somewhere in RSSFeed's method. – Maciek Sienkiewicz Mar 20 '16 at 18:12
  • 1
    The stack trace tells you **exactly** wherethe exception is thrown. Read it. And read the answers to the duplicate question. – JB Nizet Mar 20 '16 at 18:15
  • so I have already know where exactly exception is but still do not know why. I read all the answers in duplicate question but i am still confused. – Maciek Sienkiewicz Mar 20 '16 at 18:24
  • 1
    The stack trace and the exception stack trace must be **in the question itself**. You claim that the exception is at line 28 of RSSParser.java, and this line, according to what you posted, is `noteName = "description";`. There is no way for this line of code to throw a NPE. Post the real code, and the real stack trace. But before doing that, use your debugger to know what is null. – JB Nizet Mar 20 '16 at 18:41

1 Answers1

0

In your Feed class

 public static List<String> entries = new ArrayList<String>();

In the RssParser change

private Feed feed = new Feed();

feed.entries.add(feed.toString());

For

private Feed feed;

and inside the for loop

feed = new Feed()
Feed.entries.add(feed.toString());
jonhid
  • 2,075
  • 1
  • 11
  • 18
  • I did but nothing has changed. – Maciek Sienkiewicz Mar 20 '16 at 18:15
  • In the RssFeed comment those lines //noteName = "author"; and //feed.setAuthor(partOfObject.item(0).getFirstChild().getNodeValue()); and see what happens.. I see in the xml there is no nodes with this names – jonhid Mar 20 '16 at 18:31