0
我剛開始開發Android應用程序。我在網絡方面遇到了一些問題。如果我運行下面的代碼我得到一個「未知錯誤」異常消息:Android - 未知嘗試使用聯網的錯誤
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.client.ClientProtocolException;
import.org.apache.http.client.methods.HttpGet;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class Menu extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
DefaultHttpClient client = new DefaultHttpClient();
HttpGet method = new HttpGet("http://www.google.com");
try {
client.execute(method);
TextView t = (TextView) findViewById(R.id.myTextView);
t.setText("Ok");
} catch (ClientProtocolException e) {
TextView t = (TextView) findViewById(R.id.myTextView);
t.setText(e.getMessage());
} catch (IOException e) {
TextView t = (TextView) findViewById(R.id.myTextView);
t.setText(e.getMessage());
}
}
}
我已經lookign了錯誤,它似乎相當普遍。這是模擬器上DNS解析的問題。但是,我可以在模擬器上使用瀏覽器而不會出現問題,並訪問我想要的任何網站。我也嘗試用IP地址替換域名,但沒有運氣。
我該如何解決這個問題?我正在使用Windows Vista並在Eclipse中使用ADT插件進行開發。