作业帮 > 综合 > 作业

类型转换异常!Element element = (Element)node.item(j);

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/26 16:29:24
类型转换异常!Element element = (Element)node.item(j);
加星号处为错误地方!运行时老报类型转换异常!
public class Test {
public static void main(String[] args) throws Exception {


DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();


DocumentBuilder db = dbf.newDocumentBuilder();;



Document doc =db.parse("phone.xml");
NodeList list =doc.getElementsByTagName("Brand");
for(int i=0;i
for(int j=0;j
再问: 输出的还是那个错误··· Exception in thread "main" java.lang.ClassCastException: com.sun.org.apache.xerces.internal.dom.DeferredTextImpl cannot be cast to org.w3c.dom.Element at pack.Test.main(Test.java:41)
再答: http://zhidao.baidu.com/question/401691349.html 看一下这个,看有没有帮助