【问题标题】:Host is unresolved: api.twitter.com:80主机未解析:api.twitter.com:80
【发布时间】:2012-01-02 06:59:45
【问题描述】:

我在执行我的 android 应用程序时遇到此错误:

Host is unresolved: api.twitter.com:80
Relevant discussions can be on the Internet at:
http://www.google.co.jp/search?q=10f5ada3 or
http://www.google.co.jp/search?q=dceba048
TwitterException{exceptionCode=[10f5ada3-dceba048 10f5ada3-dceba01e], statusCode=-1, retryAfter=-1, rateLimitStatus=null, featureSpecificRateLimitStatus=null, version=2.2.5}

虽然我已经设置了适当的权限.. 这是我的代码:

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.abc"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="8" />
    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >

            <activity
            android:label="test1"
            android:name=".A1Activity" 
            android:launchMode="singleTask">
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

            <intent-filter>
                           <action android:name="android.intent.action.VIEW" />
                           <category android:name="android.intent.category.DEFAULT" />
                           <category android:name="android.intent.category.BROWSABLE" />
                           <data android:scheme="twitterapp" android:host="callback" />
            </intent-filter>
        </activity>

     <activity class=".screen2" android:label="test2" android:name=".screen2">
      </activity>
    </application>

</manifest>

我的文件代码是:

public class A1Activity extends Activity {

         private static final String PREF_ACCESS_TOKEN = "accessToken"; // Called when the activity is first created.      
         private static final String PREF_ACCESS_TOKEN_SECRET = "accessTokenSecret";// Name to store the users access token secret   
         public final static String CONSUMER_KEY = "abc"; // "your key here";
         public final static String CONSUMER_SECRET = "def"; // "your secret key here";     
         private static final String CALLBACK_URL = "twitterapp://callback";// The url that Twitter will redirect to after a user log
         private SharedPreferences mPrefs;     // Preferences to store a logged in users credentials 
         private Twitter mTwitter;// = new TwitterFactory().getInstance(); 
         private RequestToken mReqToken;/** The request token signifies the unique ID of the request you are sending to twitter  */
         public int returnFlag=0;

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);

                mPrefs = getSharedPreferences("twitterPrefs", MODE_PRIVATE);            
                mTwitter = new TwitterFactory().getInstance();       
                mTwitter.setOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET);
                Button mLoginButton = (Button) findViewById(R.id.login_button);
                mLoginButton.setOnClickListener(new View.OnClickListener() {
                    public void onClick(View v) {
                        System.out.println("1");
                        loginNewUser();
                        System.out.println("7.saveAccessToken ");
                        //Intent screenEnterZip = new Intent(A1Activity.this, screen2.class);
                        //startActivity(screenEnterZip);// Perform action on click                
                        }
                    });
                }


        public void loginNewUser() {        
            try { 
                    System.out.println("2");
                    mReqToken = mTwitter.getOAuthRequestToken(CALLBACK_URL);
                    System.out.println("2.1");
                    WebView twitterSite = new WebView(this);
                    System.out.println("2.2");
                    twitterSite.loadUrl(mReqToken.getAuthenticationURL());
                    System.out.println("2.3");
                    setContentView(twitterSite);                
                    //Status status = mTwitter.updateStatus("My First Tweet ... ");                
                    //System.out.println("Successfully updated the status to [" + status.getText() + "].");                
                    System.out.println("1. loginNewUser Completes ");
                }
            catch (TwitterException e) {
                System.out.println("ExceptioniZ "+e);
                Toast.makeText(this, "Twitter Login error, try again later", Toast.LENGTH_SHORT).show();
            }
        }

应用在模拟器中打开,屏幕显示登录按钮。但是在登录按钮上单击它现在正在抛出常规错误,而该应用程序在几个小时前正在运行......
谁能提出可能是什么问题..?

【问题讨论】:

  • 我刚发现Android模拟器缺少3G图标..怎么办?
  • 它可能是为了表明您有 3G(高速)连接。
  • 我不确定你是否可以用 android 做到这一点。你能ping通“api.twitter.com”吗?
  • stackoverflow.com/questions/7598817/…这个人说要检查模拟器...

标签: java android exception twitter twitter4j


【解决方案1】:

您的模拟器中可能没有互联网连接。

在模拟器中打开浏览器并输入“http://api.twitter.com”。这可能行不通。在你的本地电脑上做同样的事情,它应该在那里工作。

【讨论】:

  • 是的,但它在几个小时前就在那里.. 怎么样.. 我该如何修复它 Udo
  • 推特今天很不稳定,所以可能是这样。
  • 我也遇到了同样的问题。它起作用了,我离开了,回来了,它没有起作用。关闭模拟器并重新启动修复它。
  • 谢谢,因为我的设备没有连接到互联网,所以我得到了这个异常。当我将设备连接到互联网时,一切正常。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-11-29
  • 2021-05-18
  • 2018-07-14
  • 1970-01-01
相关资源
最近更新 更多