我正在尝试从 url 获取 HTML 源代码,然后将其传递给字符串。在我按下调试按钮后,它会询问我是否要打开调试器(代码编译得很好。)
调试器:ActivityThread.performLaunchActivity(ActivityThread$ActivityClientRecord, Intent) 行:2180
说 e > cause > "java.lang.NullPointerException" 和 "detailMessage null"。
所以我知道这是一个 NullPointerException 但看不到在哪里。
LogCat 说的唯一内容是:
08-14 00:34:10.437: E/Trace(1784): error opening trace file: No such file or directory (2)
08-14 00:34:10.437: I/System.out(1784): Sending WAIT chunk
08-14 00:34:10.437: I/dalvikvm(1784): Debugger is active
08-14 00:34:10.644: I/System.out(1784): Debugger has connected
08-14 00:34:10.644: I/System.out(1784): waiting for debugger to settle...
08-14 00:34:11.867: I/System.out(1784): debugger has settled (1300)
08-14 00:34:13.428: D/dalvikvm(1784): threadid=1: still suspended after undo (sc=1 dc=1)
我真的不知道还有什么信息可以给你。:/
我使用的代码是(这是 GetCode 类)
public String html;
public void getSourceCode() throws ClientProtocolException, IOException {
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet("http://www.novasoftware.se/webviewer/(S(pisjjgujku50by55lpbdl1a2))/design1.aspx?schoolid=18200&code=83310");
HttpResponse response = client.execute(request);
html = "";
InputStream in = response.getEntity().getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
StringBuilder str = new StringBuilder();
String line = null;
while((line = reader.readLine()) != null)
{
str.append(line);
}
in.close();
html = str.toString();
System.out.println("html");
}
然后在主类中我只是尝试打印代码。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
doStuff();
}
private void doStuff() {
try {
getcode.getSourceCode();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(getcode.html);
}