-1

ライブラリ Twitter4J を使用して apk を Twitter に接続しています。ツイッターで情報発信したい。私はこの方法を使用しています:

try {
                AccessToken accessToken = new AccessToken(prefs.getTwitterToken(),prefs.getTwitterTokenSecret());
                Twitter twitter = new TwitterFactory().getOAuthAuthorizedInstance(MyConstants.TWITTER_CONSUMER_KEY, 
                        MyConstants.TWITTER_CONSUMER_SECRET ,accessToken);

                String shareText= "Super";
                Status status = twitter.updateStatus(shareText);
                int statusId = (int)status.getId();

                Toast.makeText(getActivity(), "Tweet Successfull", Toast.LENGTH_LONG).show();

            } catch (TwitterException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                Toast.makeText(getActivity(), e.toString(), Toast.LENGTH_LONG).show();
            }

しかし、私はエラーが発生します:

04-28 20:42:17.829: E/AndroidRuntime(1537): FATAL EXCEPTION: main
04-28 20:42:17.829: E/AndroidRuntime(1537): android.os.NetworkOnMainThreadException
04-28 20:42:17.829: E/AndroidRuntime(1537):     at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1118)
04-28 20:42:17.829: E/AndroidRuntime(1537):     at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
04-28 20:42:17.829: E/AndroidRuntime(1537):     at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
04-28 20:42:17.829: E/AndroidRuntime(1537):     at java.net.InetAddress.getAllByName(InetAddress.java:214)
04-28 20:42:17.829: E/AndroidRuntime(1537):     at libcore.net.http.HttpConnection.<init>(HttpConnection.java:70)
04-28 20:42:17.829: E/AndroidRuntime(1537):     at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
04-28 20:42:17.829: E/AndroidRuntime(1537):     at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:340)
04-28 20:42:17.829: E/AndroidRuntime(1537):     at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:87)
04-28 20:42:17.829: E/AndroidRuntime(1537):     at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
04-28 20:42:17.829: E/AndroidRuntime(1537):     at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:315)
04-28 20:42:17.829: E/AndroidRuntime(1537):     at libcore.net.http.HttpEngine.connect(HttpEngine.java:310)
04-28 20:42:17.829: E/AndroidRuntime(1537):     at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:289)
04-28 20:42:17.829: E/AndroidRuntime(1537):     at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:239)
04-28 20:42:17.829: E/AndroidRuntime(1537):     at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:80)
04-28 20:42:17.829: E/AndroidRuntime(1537):     at libcore.net.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:188)
04-28 20:42:17.829: E/AndroidRuntime(1537):     at twitter4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:150)
04-28 20:42:17.829: E/AndroidRuntime(1537):     at twitter4j.internal.http.HttpClientWrapper.request(HttpClientWrapper.java:61)
04-28 20:42:17.829: E/AndroidRuntime(1537):     at twitter4j.internal.http.HttpClientWrapper.post(HttpClientWrapper.java:98)
04-28 20:42:17.829: E/AndroidRuntime(1537):     at twitter4j.TwitterImpl.post(TwitterImpl.java:1871)
04-28 20:42:17.829: E/AndroidRuntime(1537):     at twitter4j.TwitterImpl.updateStatus(TwitterImpl.java:241)
04-28 20:42:17.829: E/AndroidRuntime(1537):     at pl.spot.tccsc.fragments.TeamsTeamOwnerFragment$1.onClick(TeamsTeamOwnerFragment.java:108)
04-28 20:42:17.829: E/AndroidRuntime(1537):     at android.view.View.performClick(View.java:4211)
04-28 20:42:17.829: E/AndroidRuntime(1537):     at android.view.View$PerformClick.run(View.java:17267)
04-28 20:42:17.829: E/AndroidRuntime(1537):     at android.os.Handler.handleCallback(Handler.java:615)
04-28 20:42:17.829: E/AndroidRuntime(1537):     at android.os.Handler.dispatchMessage(Handler.java:92)
04-28 20:42:17.829: E/AndroidRuntime(1537):     at android.os.Looper.loop(Looper.java:137)
04-28 20:42:17.829: E/AndroidRuntime(1537):     at android.app.ActivityThread.main(ActivityThread.java:4898)
04-28 20:42:17.829: E/AndroidRuntime(1537):     at java.lang.reflect.Method.invokeNative(Native Method)
04-28 20:42:17.829: E/AndroidRuntime(1537):     at java.lang.reflect.Method.invoke(Method.java:511)
04-28 20:42:17.829: E/AndroidRuntime(1537):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
04-28 20:42:17.829: E/AndroidRuntime(1537):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
04-28 20:42:17.829: E/AndroidRuntime(1537):     at dalvik.system.NativeStart.main(Native Method)

AndroidでTwitterに投稿したり、その問題を解決したりするにはどうすればよいですか?

4

1 に答える 1