2013-10-07 64 views
1

我無法使用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

+0

你有你的libs文件夾中的jar? – Raghunandan

+0

抱歉已經更新了這個問題。 – misguided

+0

立即檢查我的帖子 – Raghunandan

回答

1

你有NetworkOnMainThreadException

http://developer.android.com/reference/android/os/NetworkOnMainThreadException.html

你是在UI線程上運行的網絡相關操作。使用threadAsynctask

http://developer.android.com/reference/android/os/AsyncTask.html

  new TheTask().execute(); 
      // can pass parameters to doinbackground or 
      // can pass param to constructor of asycntask 

然後

class TheTask extends AsyncTask<Void, Void, Void> { 

    protected void doInBackground(Void... params) { 
     try { 
      // your twitter code here 
      // do not update ui ere 
     } catch (Exception e) { 


     } 
     return null; 
    } 
    @Override 
    protected void onPostExecute(Void result) { 
    super.onPostExecute(result);  
    } 
} 
+0

它讓我這個解析錯誤,並返回給我一個網站,而不是在http://yamba.marakana.com/api發佈推文E/MAINACTIVITY:winterwell.jtwitter.TwitterException $解析:<!DOCTYPE html – ashim888

相關問題