我正在使用jGRASP版本2.0.0_03。 (使用jdk1.7.0_25)用Java编写的程序, 我尝试用XML和Java学习之用......这就是我试图使用Java创建XML文档:我应该怎么做才能在java中使用ELement类
private void writeFile()
{
dFact = DocumentBuilderFactory.newInstance();
build = dFact.newDocumentBuilder();
doc = build.newDocument();
Element root = doc.createElement("outPutResult");
doc.appendChild(root);
for(Result r:resultList)
{
Element title = doc.createElement("Title");
title.appendChild(doc.createTextNode(r.getTitle));
root.appendChild(title);
Element address = doc.createElement("Address");
address.appendChild(doc.createTextNode(r.getAddress));
root.appendChild(address);
}
}//End of Write function
我得到的错误作为:
hw12.java:38: error: cannot find symbol
Document doc;
^
symbol: class Document
location: class hw12
hw12.java:246: error: cannot find symbol
Element root = doc.createElement("outPutResult");
^
symbol: class Element
location: class hw12
我该输入什么来使用这些类?
您是否配置了类路径?当java编译器找不到某些东西,数据类型,调用方法时会发生此错误。 –
不,它是*不是*类路径问题 - 这将是运行时错误,而不是编译器错误。 –