原文已发布在android论坛,但是没人回应,悬赏了100没人理我。
原文链接:
http://bbs.csdn.net/topics/390566835?page=1#post-395413355
程序很简单:
main里:
String urlString = "http://ftp121455.host181.web522.com/daoyutwo.txt";
InputStream inputStream;
onCreat里:
try {
URL url = new URL(urlString);
//方法1:
inputStream = url.openStream();
Log.e("internet", "got InputStream");
//方法2:
URLConnection urlConnection = url.openConnection();
inputStream = urlConnection.getInputStream();
Log.e("internet", "got InputStream");
//方法3:
URLConnection urlConnection = url.openConnection();
HttpURLConnection httpURLConnection = (HttpURLConnection)urlConnection;
inputStream = httpURLConnection.getInputStream();
Log.e("internet", "got InputStream");
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
用真机测试,结果每次执行到"inputStream = xxx"都会报错:
java.net.UnKnownHostException: http://ftp121455.host181.web522.com
有的时候手机上同样的两个工程,函数都一样的,一个可以另一个不可以。
用模拟器完美运行。
求指点该怎么办?用手机怎么都不行,都要急死了。
你把http://去掉看看
最好不要在主线程里面访问网络,不然会出问题的,可以新建一个线程异步加载,楼主说的同样两个工程,所使用的Android版本不一样吧
累了老两口开口科技巨化股份惹润滑剂经济回锅肉儿童规划