作者badhabit (习惯坏习惯)
看板AndroidDev
标题[问题] java.net.UnknownHostException
时间Fri Apr 22 00:15:04 2011
开发层: (应用/框架/库/核心)
应用
问题:
有部份网友说无法使用,尤其是DHD最多
错误代码是:java.net.UnknownHostException:Host is unresoled:www.cpbl.com.tw:80
我是用模拟器跟I9000测都正常...
输入:
String cpbl_url ="
http://www.cpbl.com.tw/Standings/AllScoreqry.aspx";
预期输出:
网页资料
错误输出:
无
错误讯息:
错误代码是:java.net.UnknownHostException:Host is unresoled:www.cpbl.com.tw:80
程式码: (请多利用置底文网站)
new Thread(new Runnable() {
public void run() {
String temp= "",data = "";
try {
URL url = new URL(u);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("X-Online-Host", url.getHost());
conn.setDoInput(true);
conn.connect();
InputStream is = conn.getInputStream();
BufferedReader in = new BufferedReader(new InputStreamReader(is));
while ((temp = in.readLine()) != null){
data += temp;
}
in.close();
is.close();
data = Analytics(data);
} catch (Exception e) {
if (!haveInternet()){
data="无法连线,请检查您的网路连线";
}else{
data="错误代码:"+e.toString();
}
}
Main.this.handler.sendMessage(handler.obtainMessage(0,data));
progressDialog.cancel();
}}).start();
完整的程式码在
http://uploadmirrors.com/download/FWVL8ZRH/CPBL_Schedule.zip
补充说明:
之前在android版有版友说需要中华职棒比赛场次的app
我就顺手做了一个,不过却遇到连线的问题
实在是不知道问题出在哪里...请大家帮忙了,谢谢^^
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 218.160.210.180
1F:推 mamaya3:Nexus one跑起来没问题..用DHD浏览器直连那网址没问题吗? 04/22 03:04
2F:推 mamaya3:我猜是conn.setRequestProperty这行问题.. 04/23 03:57
3F:→ badhabit:询问了一些人,似乎是他们手机的问题,谢谢^^ 04/24 09:08