我正在尝试解析 xml 文件,但在 try-catch 中收到此“可抛出消息”
这是什么意思&我应该怎么做?
此消息:http: //i.stack.imgur.com/1cHHa.jpg
java.lang.ClassCastException:org.harmony.xml.dom.ElementImpl$ElementAttrNamedNodeMapImpl 无法转换为 android.renderscript.Element
try
{
InputStream in=getResources().openRawResource(R.raw.words);
DocumentBuilder builder=DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc=builder.parse(in, null);
Log.i("problem detect", "Line Detecting");
NodeList words=doc.getElementsByTagName("word");
items.add((Element) ((DocumentBuilderFactory)words.item(1)).getAttribute("words"));
//items.add((Element)words.item(1).getAttributes());
in.close();
}
catch (Throwable t)
{
new AlertDialog.Builder(this).setTitle("Catch").setMessage(t.toString()).show();
......................XML 文件...... ...................................
<?xml version="1.0" encoding="utf-8"?> <words> <word value="lorem" /> <word value="ipsum" /> <word value="dolor" /> <word value="sit" /> <word value="amet" /> <word value="consectetuer" /> <word value="adipiscing" /> <word value="elit" /> <word value="morbi" /> <word value="vel" /> <word value="ligula" /> <word value="vitae" /> <word value="arcu" /> <word value="aliquet" /> <word value="mollis" /> <word value="etiam" /> <word value="vel" /> <word value="erat" /> <word value="placerat" /> <word value="ante" /> <word value="porttitor" /> <word value="sodales" /> <word value="pellentesque" /> <word value="augue" /> <word value="purus" /> </words>