当前位置: 技术问答>java相关
关于变量 document 可能尚未初始化错误的问题,请帮忙看看!
来源: 互联网 发布时间:2015-03-19
本文导语: public Document updateChild() { Document document; try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); InputSource xmlFile = new InputSource("http://127.0.0.1:1001/examples/xml/personal.xml"); DocumentBuilder builder = factory.newDocumentBui...
public Document updateChild()
{
Document document;
try
{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
InputSource xmlFile = new InputSource("http://127.0.0.1:1001/examples/xml/personal.xml");
DocumentBuilder builder = factory.newDocumentBuilder();
document = builder.parse(xmlFile);
}catch (javax.xml.parsers.ParserConfigurationException tce)
{
}catch (java.io.IOException tce)
{
}catch (org.xml.sax.SAXException tce)
{
}
return document;
}
怎么处理呢??
{
Document document;
try
{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
InputSource xmlFile = new InputSource("http://127.0.0.1:1001/examples/xml/personal.xml");
DocumentBuilder builder = factory.newDocumentBuilder();
document = builder.parse(xmlFile);
}catch (javax.xml.parsers.ParserConfigurationException tce)
{
}catch (java.io.IOException tce)
{
}catch (org.xml.sax.SAXException tce)
{
}
return document;
}
怎么处理呢??
|
这样改可以编译通过
public Document updateChild()
{
Document document=null;
try
{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
InputSource xmlFile = new InputSource("http://127.0.0.1:1001/examples/xml/personal.xml");
DocumentBuilder builder = factory.newDocumentBuilder();
document = builder.parse(xmlFile);
}catch (javax.xml.parsers.ParserConfigurationException tce)
{
}catch (java.io.IOException tce)
{
}catch (org.xml.sax.SAXException tce)
{
}
return document;
}
public Document updateChild()
{
Document document=null;
try
{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
InputSource xmlFile = new InputSource("http://127.0.0.1:1001/examples/xml/personal.xml");
DocumentBuilder builder = factory.newDocumentBuilder();
document = builder.parse(xmlFile);
}catch (javax.xml.parsers.ParserConfigurationException tce)
{
}catch (java.io.IOException tce)
{
}catch (org.xml.sax.SAXException tce)
{
}
return document;
}
|
Document document=null; 用于赋初值
|
Document document=null;