当这个线程运行时我遇到了一个问题,所以我的应用程序崩溃了。我真的不明白,问题出在哪里。
public void onClick(DialogInterface dialog, int which) {
//Searching with post request
BugSenseHandler.sendEvent("Search started");
new Thread(new Runnable() {
@Override
public void run() {
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("find", etMedName.getText().toString()));
String prec = "";
if (cbPrecise.isChecked()) prec = "on";
else prec = "off";
nameValuePairs.add(new BasicNameValuePair("exact_match", prec));
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("http://mashkovsky.ru/tiki-listpages.php");
post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse resp = client.execute(post);
String html = "";
html = EntityUtils.toString(resp.getEntity());
Document doc = Jsoup.parse(html, "http://mashkovsky.ru/tiki-listpages.php");
Element content = doc.getElementById("wrapper");
wView.loadData(content.outerHtml(), "text/html", "utf-8");
MainActivity.this.removeDialog(SEARCH_DIALOG);
}
catch (ClientProtocolException e) {e.printStackTrace();}
catch (IOException e) {e.printStackTrace();}
}
}).start();
}
我在 Eclipse 的 LogCat 窗口中没有堆栈跟踪,但BugSense显示了这个简短的堆栈跟踪
java.lang.NullPointerException
at ru.pathdevel.mashkovsyreference.MainActivity$1$1.run(MainActivity.java:106)
at java.lang.Thread.run(Thread.java:856)
UPD:问题解决了。一切都在初始化中。我试图采用 main.xml 布局小部件,而不是 searchdialog.xml