0

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?

Shadow The GPT Wizard
  • 66,030
  • 26
  • 140
  • 208

1 Answers1

0

To use the validating parser, make the following changes:

spfactory.setValidating(true);

By default the value of this is set to false.

swapy
  • 1,616
  • 1
  • 15
  • 31