2 Replies Latest reply on Apr 6, 2014 12:00 PM by jwenting

    XML-parse - NullPointer


      Hi guys,


      This code is the source of the problem:

      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();


      DocumentBuilder builder = factory.newDocumentBuilder();

      Document document = builder.parse(new File("C:\\plainfile.xml"));


      The result is: document ist "null".


      I don't know the reason for this. I'm hoping for your help guys.

        • 1. Re: XML-parse - NullPointer
          This code is the source of the problem:

          Sorry - but I don't see how that is even possible.


          The code you posted does not even refer to the 'document' instance variable except to set it.


          More likely there is code that you did NOT post that is causing the problem.


          Post actual, complete, sample code that demonstrates the problem you say you are having.


          If that code is REALLY the source of the problem you should be able to provide a sample class file that has NOTHING but that code and the missing import statements for the classes you are using.

          • 2. Re: XML-parse - NullPointer

            I would expect another error to be possible from this code, a FileNotFoundException if you can't read that file (or possibly some security related exception if you have no read or write access to its location).

            An NPE as rp0248 points out won't happen until later, trying to use that Document instance if you tried running this code, ignored that earlier exception, and just assumed that the document had now been initialised.