XML 的问题?

9116 2004-07-23 05:30:36
/*==============================================================================
功能:启用或禁用某个大栏目;
参数:BchName:大栏目名称;val:true/false [true:启用/false:禁用]
返回值:设置成功:1;参数错误:2;找不到节点:-1;写入错误:0;
*/
public int setBchRun(String BchName, String val)
{
Node One = null;
System.out.println("param:" + val);
if (val.compareTo("false") != 0 && val.compareTo("true") != 0)
{
//参数错误
return 2;
}

NodeList nos = doc.getElementsByTagName("B_channel");

for (int i = 1; i < nos.getLength(); i++)
{
Node n = nos.item(i);
Element e = (Element) n;
if (e.getAttribute("name").compareTo(BchName) == 0)
{
//找到这个节点
One = n;
break;
}
}

//没有找到这个节点
if (One == null)
{
return -1;
}
//启用和关闭栏目以及他的子栏目

( (Element) One).setAttribute("run", val);
Node child = One.getFirstChild();

for (int j = 0; j < One.getChildNodes().getLength(); j++)
{
try
{
//Node oneC = children.item(j);
//System.out.println(child);
Element ee=(Element)child;
//Element ee=(Element)child;
//child = child.getNextSibling();

}
catch (Exception ex)
{
System.out.println("Error:\n" + ex);
//ex.printStackTrace();
}

}
/*
if (this.writeXML() == 1)
{
return 1;
}
else
{
return 0;
}
*/
return 80;
}

///=========================错误提示是:
java.lang.ClassCastException



at xmlreacer.JspsevConf.<init>(JspsevConf.java:50)

at xmlreacer.JspsevConf.main(JspsevConf.java:483)

java.lang.ClassCastException

at xmlreacer.JspsevConf.setBchRun(JspsevConf.java:118)

at xmlreacer.JspsevConf.<init>(JspsevConf.java:50)

at xmlreacer.JspsevConf.main(JspsevConf.java:483)

java.lang.ClassCastException

at xmlreacer.JspsevConf.setBchRun(JspsevConf.java:118)

at xmlreacer.JspsevConf.<init>(JspsevConf.java:50)

at xmlreacer.JspsevConf.main(JspsevConf.java:483)


请问是什么原因导致类型转换的错误? 谢谢!
...全文
57 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
9116 2004-07-23
  • 打赏
  • 举报
回复
希望哪位高手可以帮我解决一下?
9116 2004-07-23
  • 打赏
  • 举报
回复
问题出在这里:
for (int j = 0; j < One.getChildNodes().getLength(); j++)
{
try
{
//Node oneC = children.item(j);
//System.out.println(child);
Element ee=(Element)child;
//Element ee=(Element)child;
//child = child.getNextSibling();

}
catch (Exception ex)
{
System.out.println("Error:\n" + ex);
//ex.printStackTrace();
}

}
具体是什么原因我找不出来,很郁闷呀!

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧