-4

I keep getting a null object reference with the setter in Android. Here is the trace:

04-04 09:18:15.465 32664-1342/com.example.farhad.rssfeedfyp I/XMLHelper: TAG: rss 04-04 09:18:15.465 32664-1342/com.example.farhad.rssfeedfyp I/XMLHelper: TAG: channel 04-04 09:18:15.465 32664-1342/com.example.farhad.rssfeedfyp I/XMLHelper: TAG: link 04-04 09:18:15.465 32664-1342/com.example.farhad.rssfeedfyp I/XMLHelper: TAG: title 04-04 09:18:15.475 32664-1342/com.example.farhad.rssfeedfyp E/XMLHelper: Exception: Attempt to invoke virtual method 'void com.example.farhad.rssfeedfyp.TPostValue.setTitle(java.lang.String)' on a null object reference

the source code is available on https://github.com/farhadmiah/RssFeedFyp. would really appreciate the help!

Farhad 95
  • 9
  • 6

1 Answers1

0

On line 99 in your XML helper you only create a new item object if the element's name is item.

Then in endElement(...), you set the title if the name is title. So you encountered a title element which is not inside an item element, before creating the first item.

You should probably add an extra check if item is not null. Also null the item out to avoid unexpected data.

Daniel Zolnai
  • 16,487
  • 7
  • 59
  • 71