上载xml文件时出现空指针异常

时间:2012-06-12 11:43:02

标签: java file-upload saxparser

我有以下代码:

L2SchemaHandler handler = getSchemaHandler();        

// validate
XMLFormatValidator validator = new XMLFormatValidator(handler.elements, handler.types, handler.root);    

InputStream schemaInput = new FileInputStream(new File(xmlFilePath));

SAXParserFactory spfactory = SAXParserFactory.newInstance();
spfactory.setFeature("http://xml.org/sax/features/namespaces", true);

SAXParser parser = spfactory.newSAXParser();

//this line gives the null pointer Exception
parser.parse(schemaInput, validator);

report.addAll(validator.getReport());
this.objectsList = validator.getObjectList();
// When we know objects are valid, get duplicate objects from db
if(report.isEmpty())
    duplicateObjectsMap    = validateObjectID(validator.getObjects(),report);
    // here we need to check whether object id's exists in db
if(report.isEmpty()){//if no errors have occurred
   //        if(validateObjectID(validator.getObjects(),report))
        validateObjectsFromFile(validator.getObjects(), report , msgreport);
}

标记的行提供空指针异常,而parserschemaInputvalidator包含的对象不是空值。

为什么这一行给出空指针异常?

1 个答案:

答案 0 :(得分:0)

要使用验证解析器,请进行以下更改:

spfactory.setValidating(true);

默认情况下,this的值设置为false。