【发布时间】:2011-05-26 09:07:44
【问题描述】:
我想在我的 XML 无法解析时捕获异常。因为我对正在创建的 XML 没有任何影响,所以我不想在出现问题时捕获异常(比如错误的标签、奇怪的标志等等)。
我创建了以下代码,但它会导致崩溃。我在代码下添加了 LogCat。我不太明白 LogCat 告诉我什么......有人有帮助我的提示吗?谢谢
private void getVacatures(){
functie = getIntent().getIntExtra("Functie", 0);
stat =getIntent().getIntExtra("Statuut", 0);
regio = getIntent().getIntExtra("Straal", 0);
opl = getIntent().getIntExtra("Opleiding", 0);
final AlertDialog.Builder builder = new AlertDialog.Builder(JobList.this);
try {
Log.e("in try", "try");
/* Create a URL we want to load some xml-data from. */
URL url = new URL("C:/Users/hannelore.deblau/Desktop/TESTXML.xml");
System.out.println("URL: "+ url);
/* Get a SAXParser from the SAXPArserFactory. */
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
/* Get the XMLReader of the SAXParser we created. */
XMLReader xr = sp.getXMLReader();
/* Create a new ContentHandler and apply it to the XML-Reader*/
vacatureWebservice vs = new vacatureWebservice();
xr.setContentHandler(vs);
/* Parse the xml-data from our URL. */
xr.parse(new InputSource(url.openStream()));
/* Parsing has finished. */
/* Our ExampleHandler now provides the parsed data to us. */
arrVacatures = vs.getVacatures();
} catch (Exception e) {
builder.setTitle(R.string.Fouttitel);
builder.setMessage(R.string.XMLfout);
builder.setCancelable(false);
builder.setPositiveButton(R.string.Ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
finish();
}
});
builder.create().show();
}
//runOnUiThread(returnRes);
}
在 onCreate() 我这样做:
Handler handler = new Handler(); // This code is in the main UI activity class
handler.post(runnable= new Runnable(){
public void run(){
getVacatures();
runOnUiThread(returnRes);
}
});
Thread thread = new Thread(null, runnable, "MagentoBackground");
thread.start();
出现错误的 LogCat:http://pastebin.com/X5uk9cex
【问题讨论】:
标签: android exception dialog crash