I have the following code:
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);
}
The marked line gives Null pointer Exception while parser
, schemaInput
and validator
contaning the objects not the null value.
Why this line gives the null pointer exception?
To use the validating parser, make the following changes:
spfactory.setValidating(true);
By default the value of this is set to false.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.