0

我正在尝试将 android 应用程序与 Twitter 连接,但我不知道这部分代码有什么问题:

Thread thread = new Thread(){
            @Override
            public void run() {
                ConfigurationBuilder builder = new ConfigurationBuilder();
                builder.setOAuthConsumerKey(TWITTER_CONSUMER_KEY);
                builder.setOAuthConsumerSecret(TWITTER_CONSUMER_SECRET);
                Configuration configuration = builder.build();

                TwitterFactory factory = new TwitterFactory(configuration);
                twitter = factory.getInstance();
                try {
                    // Error is here
                    requestToken = twitter.getOAuthRequestToken(TWITTER_CALLBACK_URL); 
                    startActivity(new Intent(Intent.ACTION_VIEW, Uri
                            .parse(requestToken.getAuthorizationURL())));
                } catch (TwitterException e) {
                    e.printStackTrace();
                }
            }
        };

    thread.run();

为什么我得到 NetworkOnMainThreadException 尽管使用了新的 Thread ?谢谢你的帮助..

4

1 回答 1

9

调用thread.start()而不是thread.run(); 该run()方法不会产生新线程。

于 2013-08-08T22:54:45.480 回答