Android MySql connection error -
this question has answer here:
i have load data remote mysql database app. table contains event id, event name , event details. have last data table , show in 3 text views. tried tutorial androidhive. doesn't seem work. please help.
class retrieve data
class geteventdetails extends asynctask<string, string, string> { @override protected void onpreexecute() { super.onpreexecute(); pdialog = new progressdialog(mainactivity.this); pdialog.setmessage("loading data servers. please wait..."); pdialog.setindeterminate(false); pdialog.setcancelable(true); pdialog.show(); } /** * getting product details in background thread * */ protected string doinbackground(string... params) { // updating ui background thread runonuithread(new runnable() { public void run() { // check success tag int success; try { // building parameters //string pid="1"; list<namevaluepair> params = new arraylist<namevaluepair>(); // getting product details making http request // note product details url use request jsonobject json = jsonparser.makehttprequest( url_product_detials, "get", params); // check log json response log.d("single product details", json.tostring()); // json success tag success = json.getint(tag_success); if (success == 1) { // received product details jsonarray eventobj = json .getjsonarray(tag_event); // json array // first product object json array jsonobject event = eventobj.getjsonobject(0); // product pid found textview txteventname=(textview) findviewbyid(r.id.textview2); textview txteventdet=(textview) findviewbyid(r.id.textview3); // edit text txteventname.settext(event.getstring(tag_eventitle)); txteventdet.settext(event.getstring(tag_eventdet)); }else{ // product pid not found } } catch (jsonexception e) { e.printstacktrace(); } } }); return null; } }
the jason parsor class
import java.io.bufferedreader; import java.io.ioexception; import java.io.inputstream; import java.io.inputstreamreader; import java.io.unsupportedencodingexception; import java.util.list; import org.apache.http.httpentity; import org.apache.http.httpresponse; import org.apache.http.namevaluepair; import org.apache.http.client.clientprotocolexception; import org.apache.http.client.entity.urlencodedformentity; import org.apache.http.client.methods.httpget; import org.apache.http.client.methods.httppost; import org.apache.http.client.utils.urlencodedutils; import org.apache.http.impl.client.defaulthttpclient; import org.json.jsonexception; import org.json.jsonobject; import android.util.log; public class jsonparser { static inputstream = null; static jsonobject jobj = null; static string json = ""; // constructor public jsonparser() { } // function json url // making http post or method public jsonobject makehttprequest(string url, string method, list<namevaluepair> params) { // making http request try { // check request method if(method == "post"){ // request method post // defaulthttpclient defaulthttpclient httpclient = new defaulthttpclient(); httppost httppost = new httppost(url); httppost.setentity(new urlencodedformentity(params)); httpresponse httpresponse = httpclient.execute(httppost); httpentity httpentity = httpresponse.getentity(); = httpentity.getcontent(); }else if(method == "get"){ // request method defaulthttpclient httpclient = new defaulthttpclient(); string paramstring = urlencodedutils.format(params, "utf-8"); url += "?" + paramstring; httpget httpget = new httpget(url); httpresponse httpresponse = httpclient.execute(httpget); httpentity httpentity = httpresponse.getentity(); = httpentity.getcontent(); } } catch (unsupportedencodingexception e) { e.printstacktrace(); } catch (clientprotocolexception e) { e.printstacktrace(); } catch (ioexception e) { e.printstacktrace(); } try { bufferedreader reader = new bufferedreader(new inputstreamreader( is, "iso-8859-1"), 8); stringbuilder sb = new stringbuilder(); string line = null; while ((line = reader.readline()) != null) { sb.append(line + "\n"); } is.close(); json = sb.tostring(); } catch (exception e) { log.e("buffer error", "error converting result " + e.tostring()); } // try parse string json object try { jobj = new jsonobject(json); } catch (jsonexception e) { log.e("json parser", "error parsing data " + e.tostring()); } // return json string return jobj; } }
my error is
04-28 15:43:29.918: d/dalvikvm(8036): late-enabling checkjni 04-28 15:43:30.278: d/dalvikvm(8036): gc_for_alloc freed 78k, 12% free 9560k/10759k, paused 33ms, total 33ms 04-28 15:43:30.288: i/dalvikvm-heap(8036): grow heap (frag case) 10.705mb 437672-byte allocation 04-28 15:43:30.358: d/dalvikvm(8036): gc_concurrent freed <1k, 11% free 9986k/11207k, paused 13ms+7ms, total 70ms 04-28 15:43:30.358: d/dalvikvm(8036): wait_for_concurrent_gc blocked 55ms 04-28 15:43:30.449: d/dalvikvm(8036): gc_for_alloc freed 2k, 11% free 10211k/11463k, paused 56ms, total 57ms 04-28 15:43:30.649: d/libegl(8036): loaded /system/lib/egl/libegl_mali.so 04-28 15:43:30.759: d/libegl(8036): loaded /system/lib/egl/libglesv1_cm_mali.so 04-28 15:43:30.789: d/libegl(8036): loaded /system/lib/egl/libglesv2_mali.so 04-28 15:43:30.879: d/openglrenderer(8036): enabling debug mode 0 04-28 15:43:32.130: d/dalvikvm(8036): gc_concurrent freed 11k, 9% free 10906k/11975k, paused 4ms+6ms, total 56ms 04-28 15:43:32.130: d/dalvikvm(8036): wait_for_concurrent_gc blocked 31ms 04-28 15:43:32.200: d/dalvikvm(8036): gc_for_alloc freed <1k, 10% free 11335k/12487k, paused 47ms, total 47ms 04-28 15:43:32.290: d/dalvikvm(8036): gc_concurrent freed 3k, 8% free 11992k/12999k, paused 3ms+13ms, total 71ms 04-28 15:43:32.681: e/spannablestringbuilder(8036): span_exclusive_exclusive spans cannot have 0 length 04-28 15:43:32.681: e/spannablestringbuilder(8036): span_exclusive_exclusive spans cannot have 0 length 04-28 15:43:34.422: e/spannablestringbuilder(8036): span_exclusive_exclusive spans cannot have 0 length 04-28 15:43:34.422: e/spannablestringbuilder(8036): span_exclusive_exclusive spans cannot have 0 length 04-28 15:43:35.994: d/progressbar(8036): setprogress = 0 04-28 15:43:35.994: d/progressbar(8036): setprogress = 0, fromuser = false 04-28 15:43:35.994: d/progressbar(8036): mprogress = 0mindeterminate = false, mmin = 0, mmax = 10000 04-28 15:43:36.124: w/resourcetype(8036): failure getting entry 0x010802c8 (t=7 e=712) in package 0 (error -75) 04-28 15:43:36.474: d/androidruntime(8036): shutting down vm 04-28 15:43:36.474: w/dalvikvm(8036): threadid=1: thread exiting uncaught exception (group=0x41a162a0) 04-28 15:43:36.534: e/androidruntime(8036): fatal exception: main 04-28 15:43:36.534: e/androidruntime(8036): android.os.networkonmainthreadexception 04-28 15:43:36.534: e/androidruntime(8036): @ android.os.strictmode$androidblockguardpolicy.onnetwork(strictmode.java:1118) 04-28 15:43:36.534: e/androidruntime(8036): @ java.net.inetaddress.lookuphostbyname(inetaddress.java:385) 04-28 15:43:36.534: e/androidruntime(8036): @ java.net.inetaddress.getallbynameimpl(inetaddress.java:236) 04-28 15:43:36.534: e/androidruntime(8036): @ java.net.inetaddress.getallbyname(inetaddress.java:214) 04-28 15:43:36.534: e/androidruntime(8036): @ org.apache.http.impl.conn.defaultclientconnectionoperator.openconnection(defaultclientconnectionoperator.java:137) 04-28 15:43:36.534: e/androidruntime(8036): @ org.apache.http.impl.conn.abstractpoolentry.open(abstractpoolentry.java:164) 04-28 15:43:36.534: e/androidruntime(8036): @ org.apache.http.impl.conn.abstractpooledconnadapter.open(abstractpooledconnadapter.java:119) 04-28 15:43:36.534: e/androidruntime(8036): @ org.apache.http.impl.client.defaultrequestdirector.execute(defaultrequestdirector.java:360) 04-28 15:43:36.534: e/androidruntime(8036): @ org.apache.http.impl.client.abstracthttpclient.execute(abstracthttpclient.java:555) 04-28 15:43:36.534: e/androidruntime(8036): @ org.apache.http.impl.client.abstracthttpclient.execute(abstracthttpclient.java:487) 04-28 15:43:36.534: e/androidruntime(8036): @ org.apache.http.impl.client.abstracthttpclient.execute(abstracthttpclient.java:465) 04-28 15:43:36.534: e/androidruntime(8036): @ com.mahavega.qcdemo.jsonparser.makehttprequest(jsonparser.java:62) 04-28 15:43:36.534: e/androidruntime(8036): @ com.mahavega.qcdemo.mainactivity$geteventdetails$1.run(mainactivity.java:198) 04-28 15:43:36.534: e/androidruntime(8036): @ android.os.handler.handlecallback(handler.java:615) 04-28 15:43:36.534: e/androidruntime(8036): @ android.os.handler.dispatchmessage(handler.java:92) 04-28 15:43:36.534: e/androidruntime(8036): @ android.os.looper.loop(looper.java:137) 04-28 15:43:36.534: e/androidruntime(8036): @ android.app.activitythread.main(activitythread.java:4856) 04-28 15:43:36.534: e/androidruntime(8036): @ java.lang.reflect.method.invokenative(native method) 04-28 15:43:36.534: e/androidruntime(8036): @ java.lang.reflect.method.invoke(method.java:511) 04-28 15:43:36.534: e/androidruntime(8036): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1007) 04-28 15:43:36.534: e/androidruntime(8036): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:774) 04-28 15:43:36.534: e/androidruntime(8036): @ dalvik.system.nativestart.main(native method)
you create asynctask, put in body there in runonuithread. cancels out asynctask, equivalent of not having one. remove part, want directly in doinbackground function.
Comments
Post a Comment