[英]xml parsing exception
i'm trying to parse a xml file but in try-catch receive this "throwable message" 我正在尝试解析xml文件,但在try-catch中收到此“可抛出消息”
what mean this & what i should do? 这是什么意思,我应该怎么做?
this mesage : http://i.stack.imgur.com/1cHHa.jpg 此消息: http ://i.stack.imgur.com/1cHHa.jpg
java.lang.ClassCastException: org.harmony.xml.dom.ElementImpl$ElementAttrNamedNodeMapImpl cannot be cast to android.renderscript.Element
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 File...................................... ........................................... 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>
Fix your imports. 修复您的导入。 There's probably something like:
可能是这样的:
import android.renderscript.Element;
while for XML parsing there should be: 而对于XML解析,应该有:
import org.w3c.dom.Element;
(Or android.sax.Element
if you're on a SAX parser.) (如果您使用的是SAX解析器,则为
android.sax.Element
。)
try {
DocumentBuilder db = dbf.newDocumentBuilder();
InputSource is = new InputSource();
is.setCharacterStream(new StringReader(xml));
doc = db.parse(is);
} catch (ParserConfigurationException e) {
Log.e("Error: ", e.getMessage());
return null;
} catch (SAXException e) {
Log.e("Error: ", e.getMessage());
return null;
} catch (IOException e) {
Log.e("Error: ", e.getMessage());
return null;
}
return doc;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.