java - the listview is not working android not null pointer exception -
i trying display data website in listview
not showing data. think there error in `asynctask,
i want view 2 text json file getting.
help me learn mistake. tried using ipadress , domainname nothing works , not exception
here code
package com.itdc.shashank.avdeal1; import android.app.activity; import android.app.progressdialog; import android.os.asynctask; import android.os.bundle; import android.util.log; import android.view.menu; import android.widget.listview; import android.widget.toast; import org.apache.http.httpentity; import org.apache.http.httpresponse; import org.apache.http.client.clientprotocolexception; import org.apache.http.client.httpclient; import org.apache.http.client.methods.httpget; import org.apache.http.impl.client.defaulthttpclient; import org.apache.http.util.entityutils; import org.json.jsonarray; import org.json.jsonexception; import org.json.jsonobject; import java.io.ioexception; import java.util.arraylist; public class itemview extends activity { arraylist<item> list1; actoradapter adp; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_item_view); list1=new arraylist<item>(); log.d("hello", "notworking"); new jsonasynctask().execute("http://avdeal.in/get_all_products.php"); } public class jsonasynctask extends asynctask<string,void, boolean>{ progressdialog pd; protected void onpreexecute(){ super.onpreexecute(); pd=new progressdialog(itemview.this); pd.setmessage("please wait"); pd.settitle("connecting"); pd.show(); pd.setcancelable(false); } @override protected boolean doinbackground(string... urls) { try { httpget httppost=new httpget(urls[0]); httpclient httpclient=new defaulthttpclient(); httpresponse response=httpclient.execute(httppost); int status=response.getstatusline().getstatuscode(); if (status>0) { httpentity entity=response.getentity(); string data= entityutils.tostring(entity); jsonobject jsono=new jsonobject(data); jsonarray jsonarray=jsono.getjsonarray("item"); (int i=0;i<jsonarray.length();i++) { jsonobject object=jsonarray.getjsonobject(i); item items=new item(object.getstring("product_title"),object.getstring("product_price")); // item.setname(object.getstring("product_title")); // item.setprice(object.getstring("product_price")); list1.add(items); } } } catch (clientprotocolexception e) { e.printstacktrace(); } catch (ioexception e) { e.printstacktrace(); } catch (jsonexception e) { e.printstacktrace(); } return true; } protected void onpostexecute(boolean result){ pd.dismiss(); adp.notifydatasetchanged(); if (result==false) toast.maketext(getapplicationcontext(), "unable fetch data", toast.length_short).show(); listview lv= (listview) findviewbyid(r.id.list); adp=new actoradapter(getapplicationcontext(),r.layout.listview, list1); lv.setadapter(adp); } } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. return true; } }
this logcat when use webaddress website working
07-23 20:37:09.008 13927-14195/com.itdc.shashank.avdeal1 i/system.out﹕ [cds][dns]unable resolve host "www.avdeal.in": no address associated hostname 07-23 20:37:09.010 13927-14195/com.itdc.shashank.avdeal1 w/system.err﹕ java.net.unknownhostexception: unable resolve host "www.avdeal.in": no address associated hostname 07-23 20:37:09.019 13927-14195/com.itdc.shashank.avdeal1 w/system.err﹕ @ java.net.inetaddress.lookuphostbyname(inetaddress.java:439) 07-23 20:37:09.019 13927-14195/com.itdc.shashank.avdeal1 w/system.err﹕ @ java.net.inetaddress.getallbynameimpl(inetaddress.java:236) 07-23 20:37:09.020 13927-14195/com.itdc.shashank.avdeal1 w/system.err﹕ @ java.net.inetaddress.getallbyname(inetaddress.java:214) 07-23 20:37:09.020 13927-14195/com.itdc.shashank.avdeal1 w/system.err﹕ @ org.apache.http.impl.conn.defaultclientconnectionoperator.openconnection(defaultclientconnectionoperator.java:137) 07-23 20:37:09.020 13927-14195/com.itdc.shashank.avdeal1 w/system.err﹕ @ org.apache.http.impl.conn.abstractpoolentry.open(abstractpoolentry.java:164) 07-23 20:37:09.020 13927-14195/com.itdc.shashank.avdeal1 w/system.err﹕ @ org.apache.http.impl.conn.abstractpooledconnadapter.open(abstractpooledconnadapter.java:119) 07-23 20:37:09.021 13927-14195/com.itdc.shashank.avdeal1 w/system.err﹕ @ org.apache.http.impl.client.defaultrequestdirector.execute(defaultrequestdirector.java:365) 07-23 20:37:09.021 13927-14195/com.itdc.shashank.avdeal1 w/system.err﹕ @ org.apache.http.impl.client.abstracthttpclient.execute(abstracthttpclient.java:555) 07-23 20:37:09.022 13927-14195/com.itdc.shashank.avdeal1 w/system.err﹕ @ org.apache.http.impl.client.abstracthttpclient.execute(abstracthttpclient.java:487) 07-23 20:37:09.022 13927-14195/com.itdc.shashank.avdeal1 w/system.err﹕ @ org.apache.http.impl.client.abstracthttpclient.execute(abstracthttpclient.java:465) 07-23 20:37:09.022 13927-14195/com.itdc.shashank.avdeal1 w/system.err﹕ @ com.itdc.shashank.avdeal1.itemview$jsonasynctask.doinbackground(itemview.java:57) 07-23 20:37:09.023 13927-14195/com.itdc.shashank.avdeal1 w/system.err﹕ @ com.itdc.shashank.avdeal1.itemview$jsonasynctask.doinbackground(itemview.java:41) 07-23 20:37:09.024 13927-14195/com.itdc.shashank.avdeal1 w/system.err﹕ @ android.os.asynctask$2.call(asynctask.java:287) 07-23 20:37:09.024 13927-14195/com.itdc.shashank.avdeal1 w/system.err﹕ @ java.util.concurrent.futuretask.run(futuretask.java:234) 07-23 20:37:09.025 13927-14195/com.itdc.shashank.avdeal1 w/system.err﹕ @ android.os.asynctask$serialexecutor$1.run(asynctask.java:230) 07-23 20:37:09.025 13927-14195/com.itdc.shashank.avdeal1 w/system.err﹕ @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1080) 07-23 20:37:09.026 13927-14195/com.itdc.shashank.avdeal1 w/system.err﹕ @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:573) 07-23 20:37:09.026 13927-14195/com.itdc.shashank.avdeal1 w/system.err﹕ @ java.lang.thread.run(thread.java:838) 07-23 20:37:09.027 13927-14195/com.itdc.shashank.avdeal1 w/system.err﹕ caused by: libcore.io.gaiexception: getaddrinfo failed: eai_nodata (no address associated hostname) 07-23 20:37:09.029 13927-14195/com.itdc.shashank.avdeal1 w/system.err﹕ @ libcore.io.posix.getaddrinfo(native method) 07-23 20:37:09.029 13927-14195/com.itdc.shashank.avdeal1 w/system.err﹕ @ libcore.io.forwardingos.getaddrinfo(forwardingos.java:59) 07-23 20:37:09.030 13927-14195/com.itdc.shashank.avdeal1 w/system.err﹕ @ java.net.inetaddress.lookuphostbyname(inetaddress.java:405) 07-23 20:37:09.031 13927-14195/com.itdc.shashank.avdeal1 w/system.err﹕ ... 17 more 07-23 20:37:09.031 13927-14195/com.itdc.shashank.avdeal1 w/system.err﹕ caused by: libcore.io.errnoexception: getaddrinfo failed: etimedout (connection timed out) 07-23 20:37:09.033 13927-14195/com.itdc.shashank.avdeal1 w/system.err﹕ ... 20 more
i guess issue related url http://108.170.10.163/get_all_products.php
. check this. url showing 404(page not found) error.
edit:
as per comments @selvin nullpointerexception
too.
you need add adp.notifydatasetchanged()
after create adapter. means need this.
adp=new actoradapter(getapplicationcontext(),r.layout.listview, list1); adp.notifydatasetchanged();
Comments
Post a Comment