android - jtwitter not posting to twitter , app crashing -
i not able post twitter using jtwitter jar. following error :
10-07 15:13:39.975: e/androidruntime(2316): fatal exception: main 10-07 15:13:39.975: e/androidruntime(2316): winterwell.jtwitter.twitterexception: android.os.networkonmainthreadexception 10-07 15:13:39.975: e/androidruntime(2316): @ winterwell.jtwitter.urlconnectionhttpclient.getpage2_ex(urlconnectionhttpclient.java:297) 10-07 15:13:39.975: e/androidruntime(2316): @ winterwell.jtwitter.urlconnectionhttpclient.post(urlconnectionhttpclient.java:370) 10-07 15:13:39.975: e/androidruntime(2316): @ winterwell.jtwitter.twitter.updatestatus(twitter.java:2762) 10-07 15:13:39.975: e/androidruntime(2316): @ winterwell.jtwitter.twitter.updatestatus(twitter.java:2694) 10-07 15:13:39.975: e/androidruntime(2316): @ winterwell.jtwitter.twitter.setstatus(twitter.java:2482) 10-07 15:13:39.975: e/androidruntime(2316): @ com.example.yamba.statusactivity.onclick(statusactivity.java:29) 10-07 15:13:39.975: e/androidruntime(2316): @ android.view.view.performclick(view.java:3511) 10-07 15:13:39.975: e/androidruntime(2316): @ android.view.view$performclick.run(view.java:14105) 10-07 15:13:39.975: e/androidruntime(2316): @ android.os.handler.handlecallback(handler.java:605) 10-07 15:13:39.975: e/androidruntime(2316): @ android.os.handler.dispatchmessage(handler.java:92) 10-07 15:13:39.975: e/androidruntime(2316): @ android.os.looper.loop(looper.java:137) 10-07 15:13:39.975: e/androidruntime(2316): @ android.app.activitythread.main(activitythread.java:4446) 10-07 15:13:39.975: e/androidruntime(2316): @ java.lang.reflect.method.invokenative(native method) 10-07 15:13:39.975: e/androidruntime(2316): @ java.lang.reflect.method.invoke(method.java:511) 10-07 15:13:39.975: e/androidruntime(2316): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:784) 10-07 15:13:39.975: e/androidruntime(2316): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:551) 10-07 15:13:39.975: e/androidruntime(2316): @ dalvik.system.nativestart.main(native method) 10-07 15:13:39.975: e/androidruntime(2316): caused by: android.os.networkonmainthreadexception 10-07 15:13:39.975: e/androidruntime(2316): @ android.os.strictmode$androidblockguardpolicy.onnetwork(strictmode.java:1099) 10-07 15:13:39.975: e/androidruntime(2316): @ java.net.inetaddress.lookuphostbyname(inetaddress.java:391) 10-07 15:13:39.975: e/androidruntime(2316): @ java.net.inetaddress.getallbynameimpl(inetaddress.java:242) 10-07 15:13:39.975: e/androidruntime(2316): @ java.net.inetaddress.getallbyname(inetaddress.java:220) 10-07 15:13:39.975: e/androidruntime(2316): @ libcore.net.http.httpconnection.<init>(httpconnection.java:71) 10-07 15:13:39.975: e/androidruntime(2316): @ libcore.net.http.httpconnection.<init>(httpconnection.java:50) 10-07 15:13:39.975: e/androidruntime(2316): @ libcore.net.http.httpconnection$address.connect(httpconnection.java:351) 10-07 15:13:39.975: e/androidruntime(2316): @ libcore.net.http.httpconnectionpool.get(httpconnectionpool.java:86) 10-07 15:13:39.975: e/androidruntime(2316): @ libcore.net.http.httpconnection.connect(httpconnection.java:128) 10-07 15:13:39.975: e/androidruntime(2316): @ libcore.net.http.httpengine.opensocketconnection(httpengine.java:308) 10-07 15:13:39.975: e/androidruntime(2316): @ libcore.net.http.httpsurlconnectionimpl$httpsengine.makesslconnection(httpsurlconnectionimpl.java:460) 10-07 15:13:39.975: e/androidruntime(2316): @ libcore.net.http.httpsurlconnectionimpl$httpsengine.connect(httpsurlconnectionimpl.java:432) 10-07 15:13:39.975: e/androidruntime(2316): @ libcore.net.http.httpengine.sendsocketrequest(httpengine.java:282) 10-07 15:13:39.975: e/androidruntime(2316): @ libcore.net.http.httpengine.sendrequest(httpengine.java:232) 10-07 15:13:39.975: e/androidruntime(2316): @ libcore.net.http.httpurlconnectionimpl.connect(httpurlconnectionimpl.java:80) 10-07 15:13:39.975: e/androidruntime(2316): @ libcore.net.http.httpurlconnectionimpl.getoutputstream(httpurlconnectionimpl.java:188) 10-07 15:13:39.975: e/androidruntime(2316): @ libcore.net.http.httpsurlconnectionimpl.getoutputstream(httpsurlconnectionimpl.java:280) 10-07 15:13:39.975: e/androidruntime(2316): @ winterwell.jtwitter.urlconnectionhttpclient.post2_connect(urlconnectionhttpclient.java:409) 10-07 15:13:39.975: e/androidruntime(2316): @ winterwell.jtwitter.urlconnectionhttpclient.post2(urlconnectionhttpclient.java:379) 10-07 15:13:39.975: e/androidruntime(2316): @ winterwell.jtwitter.urlconnectionhttpclient.post(urlconnectionhttpclient.java:348) 10-07 15:13:39.975: e/androidruntime(2316): ... 15 more
my code :
public void onclick(view v) { string statustext = editstatus.gettext().tostring(); twitter twitter = new twitter("username", "password"); twitter.setstatus(statustext); log.d("statusactivity","onclicked text :"+statustext); }
i using jtwitter version 2.9.0
you have networkonmainthreadexception
.
http://developer.android.com/reference/android/os/networkonmainthreadexception.html
you running network related operation on ui thread. use thread
or asynctask
.
http://developer.android.com/reference/android/os/asynctask.html
new thetask().execute(); // can pass parameters doinbackground or // can pass param constructor of asycntask
then
class thetask extends asynctask<void, void, void> { protected void doinbackground(void... params) { try { // twitter code here // not update ui ere } catch (exception e) { } return null; } @override protected void onpostexecute(void result) { super.onpostexecute(result); } }
Comments
Post a Comment