android - When I'm in the activity and turn internet on and off, then null pointer exception occurs -
public class nrclientsfragment extends fragment{ jsonobject json; arraylist<hashmap<string, string>> arraylist; nrclientscustomlist adapter; listview listview; private static final string tag_clientname = "client name"; private static final string tag_companyname = "company name"; private static final string tag_email = "email"; private static final string tag_contactno = "contact no"; public nrclientsfragment(){} connectiondetector cd; boolean isinternetpresent; public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view v = inflater.inflate(r.layout.fragment_nrclients, container, false); log.i("sgs", "process started "); listview = (listview)v.findviewbyid(r.id.nrclientslv); arraylist = new arraylist<hashmap<string, string>>(); adapter = new nrclientscustomlist(getactivity(), arraylist); listview.setadapter(adapter); if (connectiondetector.isconnectingtointernet()) { new nrclienttask().execute(); } else{ toast.maketext(getactivity(),"try again nr",toast.length_short).show(); } return v; } private class nrclienttask extends asynctask<void, void, void> { progressdialog pd; httpresponseresult response; @override protected void onpreexecute() { super.onpreexecute(); pd = progressdialog.show(getactivity(), null, "loading...", false, false); } protected void doinbackground(void... params) { log.i("sgs", "calling web service nr clients fragment"); soapwebservicecallnopara servicecall = new soapwebservicecallnopara(); response = servicecall.callservice(getactivity(), soapwebservicecallnopara.web_nrclients); log.i("sgs", "got response web service"); try { if( response == null || response.equals("")) { toast.maketext(getactivity(),"null values",toast.length_short).show(); return null; } else{ jsonarray arr = new jsonarray(response.getresponse()); (int = 0; < arr.length(); i++) { hashmap<string, string> map = new hashmap<string, string>(); jsonobject obj = arr.getjsonobject(i); map.put("clientname", obj.getstring(tag_clientname)); map.put("companyname", obj.getstring(tag_companyname)); map.put("email", obj.getstring(tag_email)); map.put("contactno", obj.getstring(tag_contactno)); arraylist.add(map); log.i("sgs", "all set adapter"); log.i("sgs", obj.getstring(tag_clientname)); log.i("sgs", obj.getstring(tag_companyname)); log.i("sgs", obj.getstring(tag_email)); log.i("sgs", obj.getstring(tag_contactno)); }} } catch (jsonexception e) { e.printstacktrace(); } return null; } @override protected void onpostexecute(void result) { adapter.notifydatasetchanged(); pd.dismiss(); } } }
output of logcat:
05-12 11:55:16.597: e/test(30875): exception 05-12 11:55:16.597: d/dalvikvm(30875): threadid=13: notify debugger 05-12 11:55:16.597: d/dalvikvm(30875): threadid=13 (asynctask #3): calling run() 05-12 11:55:16.599: e/androidruntime(30875): fatal exception: asynctask #2 05-12 11:55:16.599: e/androidruntime(30875): java.lang.runtimeexception: error occured while executing doinbackground() 05-12 11:55:16.599: e/androidruntime(30875): @ android.os.asynctask$3.done(asynctask.java:299) 05-12 11:55:16.599: e/androidruntime(30875): @ java.util.concurrent.futuretask.finishcompletion(futuretask.java:352) 05-12 11:55:16.599: e/androidruntime(30875): @ java.util.concurrent.futuretask.setexception(futuretask.java:219) 05-12 11:55:16.599: e/androidruntime(30875): @ java.util.concurrent.futuretask.run(futuretask.java:239) 05-12 11:55:16.599: e/androidruntime(30875): @ android.os.asynctask$serialexecutor$1.run(asynctask.java:230) 05-12 11:55:16.599: e/androidruntime(30875): @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1080) 05-12 11:55:16.599: e/androidruntime(30875): @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:573) 05-12 11:55:16.599: e/androidruntime(30875): @ java.lang.thread.run(thread.java:838) 05-12 11:55:16.599: e/androidruntime(30875): caused by: java.lang.nullpointerexception 05-12 11:55:16.599: e/androidruntime(30875): @ org.json.jsontokener.nextcleaninternal(jsontokener.java:116) 05-12 11:55:16.599: e/androidruntime(30875): @ org.json.jsontokener.nextvalue(jsontokener.java:94) 05-12 11:55:16.599: e/androidruntime(30875): @ org.json.jsonarray.<init>(jsonarray.java:87) 05-12 11:55:16.599: e/androidruntime(30875): @ org.json.jsonarray.<init>(jsonarray.java:103) 05-12 11:55:16.599: e/androidruntime(30875): @ com.example.sgs.slidingmenu.nrclientsfragment$nrclienttask.doinbackground(nrclientsfragment.java:104) 05-12 11:55:16.599: e/androidruntime(30875): @ com.example.sgs.slidingmenu.nrclientsfragment$nrclienttask.doinbackground(nrclientsfragment.java:1) 05-12 11:55:16.599: e/androidruntime(30875): @ android.os.asynctask$2.call(asynctask.java:287) 05-12 11:55:16.599: e/androidruntime(30875): @ java.util.concurrent.futuretask.run(futuretask.java:234) 05-12 11:55:16.599: e/androidruntime(30875): ... 4 more 05-12 11:55:16.727: v/inputmethodmanager(30875): focusout: android.widget.listview{4146c400 vfed.vc. .f...... -324,0-36,778 #7f0a0002 app:id/list_slidermenu} mservedview=android.widget.listview{4146c400 vfed.vc. .f...... -324,0-36,778 #7f0a0002 app:id/list_slidermenu} winfocus=false 05-12 11:55:16.856: d/openglrenderer(30875): flushing caches (mode 0) 05-12 11:55:16.882: d/openglrenderer(30875): flushing caches (mode 0) 05-12 11:55:16.915: d/openglrenderer(30875): flushing caches (mode 1) 05-12 11:55:16.920: d/openglrenderer(30875): flushing caches (mode 0) 05-12 11:55:16.929: e/windowmanager(30875): activity com.example.sgs.mainactivity has leaked window com.android.internal.policy.impl.phonewindow$decorview{41785fc8 v.e..... r......d 0,0-513,144} added here 05-12 11:55:16.929: e/windowmanager(30875): android.view.windowleaked: activity com.example.sgs.mainactivity has leaked window com.android.internal.policy.impl.phonewindow$decorview{41785fc8 v.e..... r......d 0,0-513,144} added here 05-12 11:55:16.929: e/windowmanager(30875): @ android.view.viewrootimpl.<init>(viewrootimpl.java:412) 05-12 11:55:16.929: e/windowmanager(30875): @ android.view.windowmanagerglobal.addview(windowmanagerglobal.java:218) 05-12 11:55:16.929: e/windowmanager(30875): @ android.view.windowmanagerimpl.addview(windowmanagerimpl.java:69) 05-12 11:55:16.929: e/windowmanager(30875): @ android.app.dialog.show(dialog.java:293) 05-12 11:55:16.929: e/windowmanager(30875): @ android.app.progressdialog.show(progressdialog.java:116) 05-12 11:55:16.929: e/windowmanager(30875): @ android.app.progressdialog.show(progressdialog.java:104) 05-12 11:55:16.929: e/windowmanager(30875): @ com.example.sgs.slidingmenu.nrclientsfragment$nrclienttask.onpreexecute(nrclientsfragment.java:79) 05-12 11:55:16.929: e/windowmanager(30875): @ android.os.asynctask.executeonexecutor(asynctask.java:586) 05-12 11:55:16.929: e/windowmanager(30875): @ android.os.asynctask.execute(asynctask.java:534) 05-12 11:55:16.929: e/windowmanager(30875): @ com.example.sgs.slidingmenu.nrclientsfragment.oncreateview(nrclientsfragment.java:60) 05-12 11:55:16.929: e/windowmanager(30875): @ android.app.fragment.performcreateview(fragment.java:1695) 05-12 11:55:16.929: e/windowmanager(30875): @ android.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:885) 05-12 11:55:16.929: e/windowmanager(30875): @ android.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1057) 05-12 11:55:16.929: e/windowmanager(30875): @ android.app.backstackrecord.run(backstackrecord.java:694) 05-12 11:55:16.929: e/windowmanager(30875): @ android.app.fragmentmanagerimpl.execpendingactions(fragmentmanager.java:1435) 05-12 11:55:16.929: e/windowmanager(30875): @ android.app.fragmentmanagerimpl$1.run(fragmentmanager.java:441) 05-12 11:55:16.929: e/windowmanager(30875): @ android.os.handler.handlecallback(handler.java:725) 05-12 11:55:16.929: e/windowmanager(30875): @ android.os.handler.dispatchmessage(handler.java:92) 05-12 11:55:16.929: e/windowmanager(30875): @ android.os.looper.loop(looper.java:153) 05-12 11:55:16.929: e/windowmanager(30875): @ android.app.activitythread.main(activitythread.java:5299) 05-12 11:55:16.929: e/windowmanager(30875): @ java.lang.reflect.method.invokenative(native method) 05-12 11:55:16.929: e/windowmanager(30875): @ java.lang.reflect.method.invoke(method.java:511) 05-12 11:55:16.929: e/windowmanager(30875): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:833) 05-12 11:55:16.929: e/windowmanager(30875): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:600) 05-12 11:55:16.929: e/windowmanager(30875): @ dalvik.system.nativestart.main(native method)
resolved
i making mistake here if( response == null || response.equals(""))
when changed above line if( response.getresponse() == null || response.getresponse().equals(""))
problem solved.
Comments
Post a Comment