我正在尝试将我的应用程序与 Twitter 集成。但是我遇到了一些错误。我已经使用了这个站点的代码。我为我的应用创建了一个 API。我已将网站的 URL 设置为http://www.androidhive.info并将回调 URL 设置为http://androidhive.info。我更新了我的消费者和消费者密钥。
我不确定为什么会收到此错误。我在此处附加了错误 logcat:
03-18 21:36:13.971: E/AndroidRuntime(1339): FATAL EXCEPTION: main
03-18 21:36:13.971: E/AndroidRuntime(1339): android.os.NetworkOnMainThreadException
03-18 21:36:13.971: E/AndroidRuntime(1339): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1084)
03-18 21:36:13.971: E/AndroidRuntime(1339): at java.net.InetAddress.lookupHostByName(InetAddress.java:391)
03-18 21:36:13.971: E/AndroidRuntime(1339): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:242)
03-18 21:36:13.971: E/AndroidRuntime(1339): at java.net.InetAddress.getAllByName(InetAddress.java:220)
03-18 21:36:13.971: E/AndroidRuntime(1339): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:71)
03-18 21:36:13.971: E/AndroidRuntime(1339): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
03-18 21:36:13.971: E/AndroidRuntime(1339): at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:351)
03-18 21:36:13.971: E/AndroidRuntime(1339): at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:86)
03-18 21:36:13.971: E/AndroidRuntime(1339): at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
03-18 21:36:13.971: E/AndroidRuntime(1339): at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:308)
03-18 21:36:13.971: E/AndroidRuntime(1339): at libcore.net.http.HttpEngine.connect(HttpEngine.java:303)
03-18 21:36:13.971: E/AndroidRuntime(1339): at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:282)
03-18 21:36:13.971: E/AndroidRuntime(1339): at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:232)
03-18 21:36:13.971: E/AndroidRuntime(1339): at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:80)
03-18 21:36:13.971: E/AndroidRuntime(1339): at libcore.net.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:188)
03-18 21:36:13.971: E/AndroidRuntime(1339): at twitter4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:158)
03-18 21:36:13.971: E/AndroidRuntime(1339): at twitter4j.internal.http.HttpClientWrapper.request(HttpClientWrapper.java:65)
03-18 21:36:13.971: E/AndroidRuntime(1339): at twitter4j.internal.http.HttpClientWrapper.post(HttpClientWrapper.java:102)
03-18 21:36:13.971: E/AndroidRuntime(1339): at twitter4j.auth.OAuthAuthorization.getOAuthRequestToken(OAuthAuthorization.java:121)
03-18 21:36:13.971: E/AndroidRuntime(1339): at twitter4j.auth.OAuthAuthorization.getOAuthRequestToken(OAuthAuthorization.java:104)
03-18 21:36:13.971: E/AndroidRuntime(1339): at twitter4j.TwitterBaseImpl.getOAuthRequestToken(TwitterBaseImpl.java:276)
03-18 21:36:13.971: E/AndroidRuntime(1339): at com.androidhive.twitterconnect.MainActivity.loginToTwitter(MainActivity.java:236)
03-18 21:36:13.971: E/AndroidRuntime(1339): at com.androidhive.twitterconnect.MainActivity.access$1(MainActivity.java:223)
03-18 21:36:13.971: E/AndroidRuntime(1339): at com.androidhive.twitterconnect.MainActivity$1.onClick(MainActivity.java:123)
03-18 21:36:13.971: E/AndroidRuntime(1339): at android.view.View.performClick(View.java:3480)
03-18 21:36:13.971: E/AndroidRuntime(1339): at android.view.View$PerformClick.run(View.java:13983)
03-18 21:36:13.971: E/AndroidRuntime(1339): at android.os.Handler.handleCallback(Handler.java:605)
03-18 21:36:13.971: E/AndroidRuntime(1339): at android.os.Handler.dispatchMessage(Handler.java:92)
03-18 21:36:13.971: E/AndroidRuntime(1339): at android.os.Looper.loop(Looper.java:137)
03-18 21:36:13.971: E/AndroidRuntime(1339): at android.app.ActivityThread.main(ActivityThread.java:4340)
03-18 21:36:13.971: E/AndroidRuntime(1339): at java.lang.reflect.Method.invokeNative(Native Method)
03-18 21:36:13.971: E/AndroidRuntime(1339): at java.lang.reflect.Method.invoke(Method.java:511)
03-18 21:36:13.971: E/AndroidRuntime(1339): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
03-18 21:36:13.971: E/AndroidRuntime(1339): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
03-18 21:36:13.971: E/AndroidRuntime(1339): at dalvik.system.NativeStart.main(Native Method)