android - Rss reader with custom array adapter -
i'm making android app rss feed in android studio , i'm trying put title , description from: http://feeds.bbci.co.uk/news/rss.xml, 2 textviews using custom adapter. rss feed in tab. , each time try run program exception , problem occurs in class:
public class ladapter extends arrayadapter<info> { public ladapter(context context, arraylist<info> nfos) {super(context, 0,nfos);} @override public view getview(int position, view convertview, viewgroup parent) { // data item position info info = getitem(position); // check if existing view being reused, otherwise inflate view if (convertview == null) { convertview = layoutinflater.from(getcontext()).inflate(r.layout.basic_list_item, parent, false); } // lookup view data population textview title = (textview) convertview.findviewbyid(r.id.tit); textview description = (textview) convertview.findviewbyid(r.id.desc); title.settext(info.title); description.settext(info.description); // return completed view render on screen return convertview; } }
partial tab_1.class:
public class tab_1 extends fragment { listview mlist; arraylist<info> arrayofinfo; ladapter adapter; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view v = inflater.inflate(r.layout.tab_1, container, false); ladapter adapter = new ladapter(getactivity(), arrayofinfo); #line 44-> mlist = (listview) v.findviewbyid(r.id.list); new getrssfeed().execute("http://feeds.bbci.co.uk/news/rss.xml"); mlist.setadapter(adapter); return v; }
exception:
process: com.example.pauly.myapplication, pid: 3896 java.lang.nullpointerexception: attempt invoke interface method 'int java.util.list.size()' on null object reference @ android.widget.arrayadapter.getcount(arrayadapter.java:330) @ android.widget.listview.setadapter(listview.java:487) @ com.example.pauly.myapplication.tabs.tab_1.oncreateview(tab_1.java:43) @ android.support.v4.app.fragment.performcreateview(fragment.java:1789) @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:955) @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1138) @ android.support.v4.app.backstackrecord.run(backstackrecord.java:740) @ android.support.v4.app.fragmentmanagerimpl.execpendingactions(fragmentmanager.java:1501) @ android.support.v4.app.fragmentmanagerimpl.executependingtransactions(fragmentmanager.java:490) @ android.support.v4.app.fragmentstatepageradapter.finishupdate(fragmentstatepageradapter.java:163) @ android.support.v4.view.viewpager.populate(viewpager.java:1072) @ android.support.v4.view.viewpager.populate(viewpager.java:918) @ android.support.v4.view.viewpager.onmeasure(viewpager.java:1440) ...
ladapter adapter = new ladapter(getactivity(), arrayofinfo);
arrayofinfo null (it's not initialized), because call asynctask after arrayofinfo. data receive doinbackground method, can set arrayofinfo data in method onpostexecute in asynctask , after array set data, can call in onpostexecute
ladapter adapter = new ladapter(getactivity(), arrayofinfo); mlist.setadapter(adapter);
onpostexecute handling ui.
Comments
Post a Comment