android - Null Pointer in Adapters when Data Transmission INterupted -
i null
forcefulness closes on android app when user interrupts transmission info feed. or if net slow , seems stall null
here how handle http code:
httpclient httpclient = new defaulthttpclient(); httppost httppost = new httppost(url_select); seek { httppost.setentity(new urlencodedformentity(param)); httpresponse httpresponse = httpclient.execute(httppost); httpentity httpentity = httpresponse.getentity(); // read content = httpentity.getcontent(); } grab (exception e) { log.e("log_tag", "error in http connection " + e.tostring()); } seek { bufferedreader br = new bufferedreader( new inputstreamreader(is)); stringbuilder sb = new stringbuilder(); string line = ""; while ((line = br.readline()) != null) { sb.append(line + "\n"); } is.close(); result = sb.tostring(); } grab (exception e) { log.e("log_tag", "error converting result " + e.tostring()); } homecoming null; }
then in onpostexecute
of asynctask
, null returned here seen in logcat below:
adapter = new reviewadapter(getactivity(), r, tf); // line 1164
i assume r
null
kills it? (tf
truetype font pass in)
here r
code:
(string : reviews) { r[index] = new review(reviews.get(index), datelist.get(index), userlist.get(index), itemlist.get(index), ratings.get(index), helpfulcount.get(index), chatcounts.get(index), catlist.get(index), titlelist.get(index)); index++; }
these arraylists
populated through json
parsing php
, etc.
so question is: how handle popularly? there away avoid null? or how can gracefully throw error rather forceclose?
here logcat:
02-19 12:15:12.012: e/androidruntime(32116): fatal exception: main 02-19 12:15:12.012: e/androidruntime(32116): java.lang.nullpointerexception 02-19 12:15:12.012: e/androidruntime(32116): @ android.widget.arrayadapter.init(arrayadapter.java:310) 02-19 12:15:12.012: e/androidruntime(32116): @ android.widget.arrayadapter.<init>(arrayadapter.java:128) 02-19 12:15:12.012: e/androidruntime(32116): @ com.---.---.reviewadapter.<init>(reviewadapter.java:42) 02-19 12:15:12.012: e/androidruntime(32116): @ com.---.---.ratefragmentactivity$reviewfragment$reviewtask.onpostexecute(ratefragmentactivity.java:1164) 02-19 12:15:12.012: e/androidruntime(32116): @ com.---.---.ratefragmentactivity$reviewfragment$reviewtask.onpostexecute(ratefragmentactivity.java:1) 02-19 12:15:12.012: e/androidruntime(32116): @ android.os.asynctask.finish(asynctask.java:631) 02-19 12:15:12.012: e/androidruntime(32116): @ android.os.asynctask.access$600(asynctask.java:177) 02-19 12:15:12.012: e/androidruntime(32116): @ android.os.asynctask$internalhandler.handlemessage(asynctask.java:644) 02-19 12:15:12.012: e/androidruntime(32116): @ android.os.handler.dispatchmessage(handler.java:99) 02-19 12:15:12.012: e/androidruntime(32116): @ android.os.looper.loop(looper.java:137) 02-19 12:15:12.012: e/androidruntime(32116): @ android.app.activitythread.main(activitythread.java:5193) 02-19 12:15:12.012: e/androidruntime(32116): @ java.lang.reflect.method.invokenative(native method) 02-19 12:15:12.012: e/androidruntime(32116): @ java.lang.reflect.method.invoke(method.java:511) 02-19 12:15:12.012: e/androidruntime(32116): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:795) 02-19 12:15:12.012: e/androidruntime(32116): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:562) 02-19 12:15:12.012: e/androidruntime(32116): @ dalvik.system.nativestart.main(native method)
if first try
block throws exception, should stop there , not bother sec try
block since is
potentially not value of httpentity.getcontent();
if httpclient.execute
threw exception (which in case of poor connection.
why can't check if r
null
, nowadays error user stating connection lost?
android null nullpointerexception adapter
No comments:
Post a Comment