加载模式时获取空指针异常

时间:2012-12-03 11:51:26

标签: xsd

公共类EHValidatorSample {

public static void main(String aa[]) throws SAXException, IOException, ParserConfigurationException {

    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);
    DocumentBuilder parser = dbf.newDocumentBuilder();

    SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    //      /kmehr_elements-1_4.xsd
    Schema schema = factory.newSchema(new StreamSource(EHValidatorSample.class.getResource(
            "/xsds/ehealth-kmehr/kmehr-1_4/kmehr_elements-1_4.xsd").toString()));

    Validator validator = schema.newValidator();
    DOMSource domsrc = new DOMSource(parser.parse(new InputSource("sumehr-example.xml")));
    try {
        validator.validate(domsrc);
        System.out.println("Validation successfull!!!");
        //                  System.out.println(xmlFile.getSystemId() + " is valid");
    } catch (SAXException e) {
        System.out.println("Validation not successfull!!!");
        //                  System.out.println(xmlFile.getSystemId() + " is NOT valid");
        System.out.println("Reason: " + e.getLocalizedMessage());
    }
}

}

线程“main”java.lang.NullPointerException中的异常     在be.healthconnect.emr.common.validation.EHValidatorSample.main(EHValidatorSample.java:47)

我在加载架构时遇到了一个nullpointer(如上所述)异常。 在上面的代码片段中,我正在尝试加载一个模式,该模式将用于验证在我的应用程序中生成的xmls。

有人可以帮我找出为什么我会得到空指针异常吗?

0 个答案:

没有答案