代码如下:调试错误在bfr = new BufferedReader(new InputStreamReader(conn.getInputStream())); 因为它上面那行可以输出,下面那行就不输出了。在手机上运行时点击按钮程序直接退出。。。刚才没发代码,所以重发一个
public class HttpDownloader {
private String downloadResult;
private Handler handler;
private URL url;
//下载文本
public String download(final String urlStr) {
//MyThread t = new MyThread(urlStr);
//t.start();
new Thread(){
public void run(){
BufferedReader bfr = null;
StringBuffer sb = new StringBuffer();
try{
url = new URL(urlStr);
HttpURLConnection conn =(HttpURLConnection) url.openConnection();
Log.d("mmm","0.9-----"+conn.toString());
bfr = new BufferedReader(new InputStreamReader(conn.getInputStream()));
Log.d("mmm", "----------2.1");
String line = null;
int tmp = 0;
while ((line = bfr.readLine()) != null){
Log.d("mmm", ""+(tmp++)+"-----"+line);
sb.append(line);
}
String s = sb.toString();
Log.d("mmm","333-----"+s);
Message msg = handler.obtainMessage();
msg.obj = s;
Log.d("mmm","444---------------------");
handler.sendMessage(msg);
}catch(Exception e){
e.printStackTrace();
}finally{
if (bfr != null)
try {
bfr.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}.start();
Log.d("mmm","0.5------------------");
handler = new Handler(){
@Override
public void handleMessage(Message msg) {
Log.d("mmm","11111111111111111111");
downloadResult = (String)msg.obj;
}
};
return downloadResult;
}
------解决方案--------------------
贴子开重了??