1 Replies - 1954 Views - Last Post: 02 January 2006 - 10:37 AM Rate Topic: -----

#1 tsofras  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 18
  • Joined: 07-December 05

JAVA XML Parsing

Posted 27 December 2005 - 09:44 AM

Hello there, i am trying parsing a xml file into a document using java, but i am getting an exception. Below is the code:


import org.xml.sax.SAXException;

import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;

public class testDOM
{
  public void main (String[] args)
  {
        try
        {
            String File = "settings.xml";
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            factory.setValidating(true);
            DocumentBuilder builder = factory.newDocumentBuilder();
            builder.parse(File);
            System.out.println("\n\n----" + builder.parse(File));
        }
        catch(ParserConfigurationException pce)
        {
            pce.printStackTrace();
        }
        catch(SAXException se)
        {
            se.printStackTrace();
        }
        catch(IOException ioe)
        {
            ioe.printStackTrace();
        }
 }
}




And the exception is:
C:\j2sdk1.4.2_10\bin\java -Didea.launcher.port=7539 "-Didea.launcher.bin.path=C:\Program Files\JetBrains\IntelliJ IDEA 5.0\bin" -Dfile.encoding=windows-1253 -classpath "C:\j2sdk1.4.2_10\jre\lib\charsets.jar;C:\j2sdk1.4.2_10\jre\lib\jce.jar;C:\j2sdk1.4.2_10\jre\lib\jsse.jar;C:\j2sdk1.4.2_10\jre\lib\plugin.jar;C:\j2sdk1.4.2_10\jre\lib\rt.jar;C:\j2sdk1.4.2_10\jre\lib\sunrsasign.jar;C:\j2sdk1.4.2_10\jre\lib\ext\dnsns.jar;C:\j2sdk1.4.2_10\jre\lib\ext\ldapsec.jar;C:\j2sdk1.4.2_10\jre\lib\ext\localedata.jar;C:\j2sdk1.4.2_10\jre\lib\ext\sunjce_provider.jar;C:\j2sdk1.4.2_10;C:\Projects\testDOM\classes;C:\Dom4J\dom4j-1.6.1.jar;C:\Program Files\JetBrains\IntelliJ IDEA 5.0\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain testDOM
java.lang.NullPointerException
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:324)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:86)
Exception in thread "main" 
Process finished with exit code 1




Any ideas? I tried to compile it using dom4j library but i have a problem with the Document declaration. Any help will be appreciated
Thx in advance

Is This A Good Question/Topic? 0
  • +

Replies To: JAVA XML Parsing

#2 Programmist  Icon User is offline

  • CTO
  • member icon

Reputation: 252
  • View blog
  • Posts: 1,833
  • Joined: 02-January 06

Re: JAVA XML Parsing

Posted 02 January 2006 - 10:37 AM

I tried your code and I did not get the NullPointeException that you got.
However, I had to make the main method static before it would even compile. [ public static void main( String args[] ) ]
Try that and see what you get. If you still have problems, make sure your program is finding settings.xml.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1