java - Insertion in php from android -
this question has answer here:
i inserting data android mysql using php , json request. when event fire gives exception in logcat. sharing clogcat can have better , idea of going on , here logcat :
10-07 03:55:13.073: e/androidruntime(1665): fatal exception: main 10-07 03:55:13.073: e/androidruntime(1665): android.os.networkonmainthreadexception 10-07 03:55:13.073: e/androidruntime(1665): @ android.os.strictmode$androidblockguardpolicy.onnetwork(strictmode.java:1133) 10-07 03:55:13.073: e/androidruntime(1665): @ java.net.inetaddress.lookuphostbyname(inetaddress.java:385) 10-07 03:55:13.073: e/androidruntime(1665): @ java.net.inetaddress.getallbynameimpl(inetaddress.java:236) 10-07 03:55:13.073: e/androidruntime(1665): @ java.net.inetaddress.getallbyname(inetaddress.java:214) 10-07 03:55:13.073: e/androidruntime(1665): @ org.apache.http.impl.conn.defaultclientconnectionoperator.openconnection(defaultclientconnectionoperator.java:137) 10-07 03:55:13.073: e/androidruntime(1665): @ org.apache.http.impl.conn.abstractpoolentry.open(abstractpoolentry.java:164) 10-07 03:55:13.073: e/androidruntime(1665): @ org.apache.http.impl.conn.abstractpooledconnadapter.open(abstractpooledconnadapter.java:119) 10-07 03:55:13.073: e/androidruntime(1665): @ org.apache.http.impl.client.defaultrequestdirector.execute(defaultrequestdirector.java:360) 10-07 03:55:13.073: e/androidruntime(1665): @ org.apache.http.impl.client.abstracthttpclient.execute(abstracthttpclient.java:555) 10-07 03:55:13.073: e/androidruntime(1665): @ org.apache.http.impl.client.abstracthttpclient.execute(abstracthttpclient.java:487) 10-07 03:55:13.073: e/androidruntime(1665): @ org.apache.http.impl.client.abstracthttpclient.execute(abstracthttpclient.java:465) 10-07 03:55:13.073: e/androidruntime(1665): @ com.example.receiptorganizer.registration$1.insert(registration.java:78) 10-07 03:55:13.073: e/androidruntime(1665): @ com.example.receiptorganizer.registration$1.onclick(registration.java:58) 10-07 03:55:13.073: e/androidruntime(1665): @ android.view.view.performclick(view.java:4240) 10-07 03:55:13.073: e/androidruntime(1665): @ android.view.view$performclick.run(view.java:17721) 10-07 03:55:13.073: e/androidruntime(1665): @ android.os.handler.handlecallback(handler.java:730) 10-07 03:55:13.073: e/androidruntime(1665): @ android.os.handler.dispatchmessage(handler.java:92) 10-07 03:55:13.073: e/androidruntime(1665): @ android.os.looper.loop(looper.java:137) 10-07 03:55:13.073: e/androidruntime(1665): @ android.app.activitythread.main(activitythread.java:5103) 10-07 03:55:13.073: e/androidruntime(1665): @ java.lang.reflect.method.invokenative(native method) 10-07 03:55:13.073: e/androidruntime(1665): @ java.lang.reflect.method.invoke(method.java:525) 10-07 03:55:13.073: e/androidruntime(1665): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:737) 10-07 03:55:13.073: e/androidruntime(1665): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:553) 10-07 03:55:13.073: e/androidruntime(1665): @ dalvik.system.nativestart.main(native method)
this error comes when handling network call(making webservice call) in main thread i.e. in ui thread of application.
use asynctask or handler manage webservice call.
see answer
your async task class can
class thetask extends asynctask<void,void,void> { protected void onpreexecute() { super.onpreexecute(); //display progressdialog. } protected void doinbackground(void ...params) { //http request. not update ui here return null; } protected void onpostexecute(void result) { super.onpostexecute(result); //dismiss progressdialog. //update ui } }
and can use handler :
handler handler = new handler(); handler.post(new runnable() { @override public void run() { // todo auto-generated method stub // network call here } });
use of asynctask better solution.
Comments
Post a Comment