什么报错都没有就是一片空白,代码明明和视频中的一样
public class HttpThread extends Thread {
private String urlString;
private Handler handler;
private WebView view;
public HttpThread(String urlString, Handler handler, WebView view) {
super();
this.urlString = urlString;
this.handler = handler;
this.view = view;
}
@Override
public void run() {
// TODO Auto-generated method stub
try {
URL url = new URL(urlString);
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.setReadTimeout(5000);
connection.setRequestMethod("GET");
BufferedReader bReader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
final StringBuffer sBuffer= new StringBuffer();
String string;
if((string = bReader.readLine()) != null){
sBuffer.append(string);
Log.i("sz", string);
}
handler.post(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
view.loadData(sBuffer.toString(), "text/html; charset=gb2312", null);
}
});
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
添加回答
举报
0/150
提交
取消