android - (Solved) java.lang.NullPointerException: Attempt to invoke virtual method ... on a null object reference -
i have class called resultactivity display list of place'info. activity request server , receive json object. activity doesn't work , found error
java.lang.runtimeexception: unable start activity componentinfo{com.example.shameal/com.example.shameal.resultactivity}: java.lang.nullpointerexception: attempt invoke virtual method 'com.android.volley.toolbox.imageloader com.example.shameal.controller.appcontroller.getimageloader()' on null object reference
resultactivity
public class resultactivity extends listactivity{ private listview listview; private feedlistadapter listadapter; private list<feeditem> feeditems; @override protected void oncreate(bundle savedinstancestate) { // todo auto-generated method stub super.oncreate(savedinstancestate); ... listview = (listview) findviewbyid(r.id.list); feeditems = new arraylist<feeditem>(); listadapter = new feedlistadapter(this, feeditems); listview.setadapter(listadapter); ... }
feedlistadapter
public class feedlistadapter extends baseadapter { private activity activity; private layoutinflater inflater; private list<feeditem> feeditems; imageloader imageloader = appcontroller.getinstance().getimageloader(); public feedlistadapter(activity activity, list<feeditem> feeditems) { this.activity = activity; this.feeditems = feeditems; } @override public int getcount() { return feeditems.size(); } @override public object getitem(int location) { return feeditems.get(location); } @override public long getitemid(int position) { return position; } @override public view getview(int position, view convertview, viewgroup parent) { if (inflater == null) inflater = (layoutinflater) activity .getsystemservice(context.layout_inflater_service); if (convertview == null) convertview = inflater.inflate(r.layout.feed_item, null); if (imageloader == null) imageloader = appcontroller.getinstance().getimageloader(); textview name = (textview) convertview.findviewbyid(r.id.name); textview address = (textview) convertview .findviewbyid(r.id.address); textview description = (textview) convertview .findviewbyid(r.id.description); textview rate = (textview) convertview.findviewbyid(r.id.rate); networkimageview image = (networkimageview) convertview .findviewbyid(r.id.image); feedimageview feedimageview = (feedimageview) convertview .findviewbyid(r.id.feedimage1); feeditem item = feeditems.get(position); name.settext(item.getname()); // converting timestamp x ago format address.settext(item.getaddress()); // chcek empty status message if (!textutils.isempty(item.getdescription())) { description.settext(item.getdescription()); description.setvisibility(view.visible); } else { // status empty, remove view description.setvisibility(view.gone); } rate.settext(item.getrate()); image.setimageurl(item.getimage(), imageloader); // feed image if (item.getmenu() != null || item.getmenu() != "0") { feedimageview.setimageurl(item.getmenu(), imageloader); feedimageview.setvisibility(view.visible); feedimageview .setresponseobserver(new feedimageview.responseobserver() { @override public void onerror() { } @override public void onsuccess() { } }); } else { feedimageview.setvisibility(view.gone); } return convertview; }
}
i think error in line: listadapter = new feedlistadapter(this, feeditems); can not found solution fix it.
thanks help!
edited: followed tutorial: http://www.androidhive.info/2014/06/android-facebook-like-custom-listview-feed-using-volley/. use code of tutorial app doesn't work.
add 1 line manifest
<application android:name=".appcontroller" //this 1 android:allowbackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/apptheme">
Comments
Post a Comment