java - Android notifyDataSetChanged results in parsing idx 1 Illegal State Exception -
in main activity (localfeed) have listview connected asynctask gets data database in json format , sends baseadapter. problem notifydatasetchanged() nothing me (upon further researching got logcat output included below), have read lot of posts on here 1 android notifydatasetchanged not working , have implemented idea's nothing works. data when set adapter when have new data coming in stays same unless call setadapter again bad practice. first activity..
public class localfeed extends activity { string localstreams; edittext post; sharedpreferences myaccount,mya; string pathurl; float tlatmin,tlatmax,tlonmin,tlonmax,latitudes,longitudes; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.local_feed); // inputs used database pathurl = getresources().getstring(r.string.pathurl); // url data api localstreams = pathurl + "/api/streams"; tlatmin = myaccount.getfloat("thirtylatmin", 0.0f); tlatmax = myaccount.getfloat("thirtylatmax", 0.0f); tlonmin = myaccount.getfloat("thirtylonmin", 0.0f); tlonmax = myaccount.getfloat("thirtylonmax", 0.0f); latitudes = myaccount.getfloat("latitudes", 0.0f); longitudes = myaccount.getfloat("longitudes", 0.0f); // asynctask json data database final listview lv = (listview) findviewbyid(r.id.localfeed); new streams_async(localstreams, tlatmin, tlatmax, tlonmin, tlonmax, localfeed.this, myaccount, 1,lv).execute(); // setadapter here json data comes after onpostexecute of asynctask } @override public boolean oncreateoptionsmenu(menu menu) { menuinflater mif=getmenuinflater(); mif.inflate(r.menu.menu_local_feed, menu); return super.oncreateoptionsmenu(menu); } @override public boolean onoptionsitemselected(menuitem item) { int id = item.getitemid(); if (id == r.id.logout) { sharedpreferences settings = getsharedpreferences("userinfo", mode_private); settings.edit().clear().commit(); startactivity(new intent(localfeed.this,login.class)); return true; } return super.onoptionsitemselected(item); } }
i pass listview asynctask() since data comes there can not call adapter until onpostexecute() method. asynctask()
public class streams_async extends asynctask<string,string,string> { httpurlconnection conn; url url; string result=""; dataoutputstream wr; string stream_url; activity m; integer page; float tlatmin,tlatmax,tlonmin,tlonmax; sharedpreferences myaccount; public streams_async(string stream_url,float tlatmin,float tlatmax,float tlonmin,float tlonmax,activity m,sharedpreferences myaccount,integer page) { this.stream_url=stream_url; this.tlatmin=tlatmin; this.tlatmax=tlatmax; this.tlonmin=tlonmin; this.tlonmax=tlonmax; this.m=m; this.myaccount=myaccount; this.page=page; } @override protected void onpreexecute() { super.onpreexecute(); } @override protected string doinbackground(string... params) { // data database bufferedreader reader=null; try{ url = new url(stream_url); conn = (httpurlconnection) url.openconnection(); conn.setdooutput(true); conn.setrequestmethod("post"); conn.connect(); conn.setreadtimeout(10000); conn.setconnecttimeout(15000); string cert="thirtylatmin="+myaccount.getfloat("thirtylatmin", 0)+"&thirtylatmax="+myaccount.getfloat("thirtylatmax", 0)+"&thirtylonmin="+myaccount.getfloat("thirtylonmin", 0)+"&thirtylonmax="+myaccount.getfloat("thirtylonmax", 0)+ "&page="+page+"&pid="+myaccount.getint("id", 0); wr = new dataoutputstream(conn.getoutputstream()); wr.writebytes(cert); wr.flush(); wr.close(); reader = new bufferedreader(new inputstreamreader(conn.getinputstream())); stringbuilder sbuilder = new stringbuilder(); string line = ""; while ((line = reader.readline()) != null) { sbuilder.append(line + "\n"); } result = sbuilder.tostring(); reader.close(); conn.disconnect(); return result; } catch (exception e) { e.printstacktrace(); } return result; } @override protected void onpostexecute(string s) { super.onpostexecute(s); // data needed listview in result variable try { jsonobject jsonn = new jsonobject(result); jsonarray jarray = jsonn.getjsonarray("localstreams"); jsonobject jobject = null; jsonarray sss = new jsonarray(); (int = 0; < jarray.length(); i++) { jobject = jarray.getjsonobject(i); jobject.getstring("post"); jobject.getstring("fullname"); jobject.getint("id"); jobject.getint("myid"); jobject.getint("reputation"); jobject.getstring("city"); jobject.getstring("last_reply"); jobject.getstring("state"); sss.put(jobject); } jsonn.put("localstreams", sss); system.err.println("nnn: " + result); if (lv.getadapter() == null) { listview mm= (listview) m.findviewbyid(r.id.localfeed); localfeed_customview dmf = new localfeed_customview(jsonn, m); mm.setadapter(dmf); } else { // right here not work localfeed_customview dmf = new localfeed_customview(jsonn, m); dmf.notifydatasetchanged(); } } catch (exception e) { system.err.println("pp"+e.getmessage()); } } }
as can see problem in else statement inside onpostexecute not work; **dmf.notifydatasetchanged();**results in parsing error can not find how overcome.
public class localfeed_customview extends baseadapter { jsonobject names; context ctx; //,ra; string result=""; private layoutinflater mlayoutinflater = null; public localfeed_customview(){} public localfeed_customview(jsonobject arr,context c) { ctx = c; names = arr; mlayoutinflater = (layoutinflater)ctx.getsystemservice(context.layout_inflater_service); notifydatasetchanged(); } public void updatelist(){ notifydatasetchanged(); } @override public int getcount() { try { jsonarray jalocalstreams = names.getjsonarray("localstreams"); return jalocalstreams.length(); } catch (exception e) { toast.maketext(ctx,"error: please try again",toast.length_long).show(); return names.length(); } } @override public object getitem(int position) { return position; } @override public long getitemid(int position) { return position; } @override public view getview(int position,view convertview, viewgroup parent) { view row=convertview; myviewholder holder=null; try { if(row==null) { layoutinflater li= (layoutinflater) ctx.getsystemservice(context.layout_inflater_service); row = li.inflate(r.layout.customadapter, parent, false); holder=new myviewholder(row); row.settag(holder); } else { holder=(myviewholder)row.gettag(); } updatelist(); // populates listview jsonarray jalocalstreams = names.getjsonarray("localstreams"); system.err.println("ssd:" + names); final jsonobject jsonobject = jalocalstreams.getjsonobject(position); int a= jsonobject.getint("myid"); holder.post.settext(jsonobject.getstring("post")); holder.fullname.settext(jsonobject.getstring("fullname")); holder.city.settext(jsonobject.getstring("city")+ ", "); holder.state.settext(jsonobject.getstring("state")); holder.comments.settext(jsonobject.getint("comments")+ " comments "); holder.last_reply.settext(jsonobject.getstring("last_reply")); holder.reputation.settext(jsonobject.getstring("reputation")); jsonobject.getint("profile_id"); jsonobject.getint("id"); sharedpreferences myaccount = ctx.getsharedpreferences("userinfo", mode_private); int my_id = myaccount.getint("id", 0); return row; } catch (exception e) { e.printstacktrace(); } return row; } class myviewholder{ textview post,fullname,city,state,last_reply,comments,reputation; imagebutton reputation_add; myviewholder(view v) { post= (textview)v.findviewbyid(r.id.post); fullname= (textview)v.findviewbyid(r.id.fullname); city= (textview)v.findviewbyid(r.id.city); state= (textview)v.findviewbyid(r.id.state); last_reply= (textview)v.findviewbyid(r.id.last_reply); comments = (textview)v.findviewbyid(r.id.id); reputation= (textview)v.findviewbyid(r.id.reputation); reputation_add= (imagebutton)v.findviewbyid(r.id.reputation_add); } } }
this below problem area
else { // right here not work localfeed_customview dmf = new localfeed_customview(jsonn, m); dmf.notifydatasetchanged(); }
it goes catch statement , it's cause null, logcat it.. in else code causing error
java.lang.illegalstateexception: problem parsing idx 1 @ com.android.internal.net.networkstatsfactory.readnetworkstatsdetail(networkstatsfactory.java:300) @ com.android.server.networkmanagementservice.getnetworkstatsuiddetail(networkmanagementservice.java:1282) @ com.android.server.net.networkstatsservice.performpolllocked(networkstatsservice.java:831) @ com.android.server.net.networkstatsservice.updateifaceslocked(networkstatsservice.java:743) @ com.android.server.net.networkstatsservice.updateifaces(networkstatsservice.java:721) @ com.android.server.net.networkstatsservice.access$000(networkstatsservice.java:128) @ com.android.server.net.networkstatsservice$1.onreceive(networkstatsservice.java:612) @ android.app.loadedapk$receiverdispatcher$args.run(loadedapk.java:728) @ android.os.handler.handlecallback(handler.java:605) @ android.os.handler.dispatchmessage(handler.java:92) @ android.os.looper.loop(looper.java:137) @ android.os.handlerthread.run(handlerthread.java:60) caused by: java.io.filenotfoundexception: /proc/net/xt_qtaguid/stats: open failed: enoent (no such file or directory) @ libcore.io.iobridge.open(iobridge.java:406) @ java.io.fileinputstream.<init>(fileinputstream.java:78) @ com.android.internal.net.networkstatsfactory.readnetworkstatsdetail(networkstatsfactory.java:269) at com.android.server.networkmanagementservice.getnetworkstatsuiddetail(networkmanagementservice.java:1282) at com.android.server.net.networkstatsservice.performpolllocked(networkstatsservice.java:831) at com.android.server.net.networkstatsservice.updateifaceslocked(networkstatsservice.java:743) at com.android.server.net.networkstatsservice.updateifaces(networkstatsservice.java:721) at com.android.server.net.networkstatsservice.access$000(networkstatsservice.java:128) at com.android.server.net.networkstatsservice$1.onreceive(networkstatsservice.java:612) at android.app.loadedapk$receiverdispatcher$args.run(loadedapk.java:728) at android.os.handler.handlecallback(handler.java:605) at android.os.handler.dispatchmessage(handler.java:92) at android.os.looper.loop(looper.java:137) at android.os.handlerthread.run(handlerthread.java:60) caused by: libcore.io.errnoexception: open failed: enoent (no such file or directory) @ libcore.io.posix.open(native method) @ libcore.io.blockguardos.open(blockguardos.java:110) @ libcore.io.iobridge.open(iobridge.java:390) at java.io.fileinputstream.<init>(fileinputstream.java:78) at com.android.internal.net.networkstatsfactory.readnetworkstatsdetail(networkstatsfactory.java:269) at com.android.server.networkmanagementservice.getnetworkstatsuiddetail(networkmanagementservice.java:1282) at com.android.server.net.networkstatsservice.performpolllocked(networkstatsservice.java:831) at com.android.server.net.networkstatsservice.updateifaceslocked(networkstatsservice.java:743) at com.android.server.net.networkstatsservice.updateifaces(networkstatsservice.java:721) at com.android.server.net.networkstatsservice.access$000(networkstatsservice.java:128) at com.android.server.net.networkstatsservice$1.onreceive(networkstatsservice.java:612) at android.app.loadedapk$receiverdispatcher$args.run(loadedapk.java:728) at android.os.handler.handlecallback(handler.java:605) at android.os.handler.dispatchmessage(handler.java:92) at android.os.looper.loop(looper.java:137) at android.os.handlerthread.run(handlerthread.java:60) 09-30 03:47:45.001 36-67/? e/surfacetexture﹕ [com.exoler/com.exoler.login] drainqueuelocked: surfacetexture has been abandoned! 09-30 03:47:45.261 158-188/com.android.inputmethod.latin e/activitythread﹕ failed find provider info com.android.inputmethod.latin.dictionarypack 09-30 03:47:45.271 158-188/com.android.inputmethod.latin e/binarydictionarygetter﹕ not find dictionary pack
if list has adapter, perhaps don't need recreate one, instead adapter list, set fresh data (consider synchronization here, thread may try access of data when you're changing it) , call notifydatasetchanged():
else { localfeed_customview dmf = (localfeed_customview) lv.getadapter(); synchronized (nameslock) { dmf.names = ... } dmf.notifydatasetchanged(); }
in contrast, create new, unassigned, adapter , call notifydatasetchanged() on it. wasn't yet added list, may cause problem. anyway, in case, want refer existing adapter , update list that's shown screen.
Comments
Post a Comment