0

我有以下代码:

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);
}

标记的行给出Null 指针 Exception while parserschemaInput并且validator包含不是空值的对象。

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

4

1 回答 1

0

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

spfactory.setValidating(true);

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

于 2012-06-12T12:14:00.190 回答