我無法使用jtwitter jar發佈到twitter。我得到以下錯誤:jtwitter沒有發佈到twitter,應用程序崩潰
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): at winterwell.jtwitter.URLConnectionHttpClient.getPage2_ex(URLConnectionHttpClient.java:297)
10-07 15:13:39.975: E/AndroidRuntime(2316): at winterwell.jtwitter.URLConnectionHttpClient.post(URLConnectionHttpClient.java:370)
10-07 15:13:39.975: E/AndroidRuntime(2316): at winterwell.jtwitter.Twitter.updateStatus(Twitter.java:2762)
10-07 15:13:39.975: E/AndroidRuntime(2316): at winterwell.jtwitter.Twitter.updateStatus(Twitter.java:2694)
10-07 15:13:39.975: E/AndroidRuntime(2316): at winterwell.jtwitter.Twitter.setStatus(Twitter.java:2482)
10-07 15:13:39.975: E/AndroidRuntime(2316): at com.example.yamba.StatusActivity.onClick(StatusActivity.java:29)
10-07 15:13:39.975: E/AndroidRuntime(2316): at android.view.View.performClick(View.java:3511)
10-07 15:13:39.975: E/AndroidRuntime(2316): at android.view.View$PerformClick.run(View.java:14105)
10-07 15:13:39.975: E/AndroidRuntime(2316): at android.os.Handler.handleCallback(Handler.java:605)
10-07 15:13:39.975: E/AndroidRuntime(2316): at android.os.Handler.dispatchMessage(Handler.java:92)
10-07 15:13:39.975: E/AndroidRuntime(2316): at android.os.Looper.loop(Looper.java:137)
10-07 15:13:39.975: E/AndroidRuntime(2316): at android.app.ActivityThread.main(ActivityThread.java:4446)
10-07 15:13:39.975: E/AndroidRuntime(2316): at java.lang.reflect.Method.invokeNative(Native Method)
10-07 15:13:39.975: E/AndroidRuntime(2316): at java.lang.reflect.Method.invoke(Method.java:511)
10-07 15:13:39.975: E/AndroidRuntime(2316): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
10-07 15:13:39.975: E/AndroidRuntime(2316): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
10-07 15:13:39.975: E/AndroidRuntime(2316): at 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): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1099)
10-07 15:13:39.975: E/AndroidRuntime(2316): at java.net.InetAddress.lookupHostByName(InetAddress.java:391)
10-07 15:13:39.975: E/AndroidRuntime(2316): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:242)
10-07 15:13:39.975: E/AndroidRuntime(2316): at java.net.InetAddress.getAllByName(InetAddress.java:220)
10-07 15:13:39.975: E/AndroidRuntime(2316): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:71)
10-07 15:13:39.975: E/AndroidRuntime(2316): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
10-07 15:13:39.975: E/AndroidRuntime(2316): at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:351)
10-07 15:13:39.975: E/AndroidRuntime(2316): at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:86)
10-07 15:13:39.975: E/AndroidRuntime(2316): at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
10-07 15:13:39.975: E/AndroidRuntime(2316): at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:308)
10-07 15:13:39.975: E/AndroidRuntime(2316): at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.makeSslConnection(HttpsURLConnectionImpl.java:460)
10-07 15:13:39.975: E/AndroidRuntime(2316): at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.connect(HttpsURLConnectionImpl.java:432)
10-07 15:13:39.975: E/AndroidRuntime(2316): at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:282)
10-07 15:13:39.975: E/AndroidRuntime(2316): at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:232)
10-07 15:13:39.975: E/AndroidRuntime(2316): at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:80)
10-07 15:13:39.975: E/AndroidRuntime(2316): at libcore.net.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:188)
10-07 15:13:39.975: E/AndroidRuntime(2316): at libcore.net.http.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:280)
10-07 15:13:39.975: E/AndroidRuntime(2316): at winterwell.jtwitter.URLConnectionHttpClient.post2_connect(URLConnectionHttpClient.java:409)
10-07 15:13:39.975: E/AndroidRuntime(2316): at winterwell.jtwitter.URLConnectionHttpClient.post2(URLConnectionHttpClient.java:379)
10-07 15:13:39.975: E/AndroidRuntime(2316): at winterwell.jtwitter.URLConnectionHttpClient.post(URLConnectionHttpClient.java:348)
10-07 15:13:39.975: E/AndroidRuntime(2316): ... 15 more
我的代碼是:
public void onClick(View v) {
String statusText = editStatus.getText().toString();
Twitter twitter = new Twitter("username", "password");
twitter.setStatus(statusText);
Log.d("StatusActivity","onClicked with text :"+statusText);
}
我使用jtwitter版本2.9.0
你有你的libs文件夾中的jar? – Raghunandan
抱歉已經更新了這個問題。 – misguided
立即檢查我的帖子 – Raghunandan