Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,740,156 Members 40,428 Now Online
XDA Developers Android and Mobile Development Forum

[Q] java and xml

Tip us?
 
justinayres
Old
#1  
Junior Member - OP
Thanks Meter 0
Posts: 1
Join Date: Mar 2014
Default [Q] java and xml

something is wrong with my setup...

Eclipse Keplar
Windows 7 32bit
java 7u51

db = dbf.newDocumentBuilder(); throws ParserConfigurationError..
please help me. this file is as simple as i could make it.


import java.io.File;
import java.io.IOException;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.xml.sax.SAXException;


public class XMLHELP {

public static void main(String[] args) {

File file = new File("foo.xml");
DocumentBuilderFactory dbf;
DocumentBuilder db = null;

dbf = DocumentBuilderFactory.newInstance();
try {
db = dbf.newDocumentBuilder();
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

try {
Document doc = db.parse(file);
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

}
 
marwan.kallal
Old
#2  
marwan.kallal's Avatar
Junior Member
Thanks Meter 2
Posts: 11
Join Date: Mar 2014
ParserConfigurationError means that you misconfigured your factory.

Look here at the newInstance() method in the DocumentBuilderFactory API.
That tells you where it looks for configurations if you don't supply any. One of those files may be messed up or out of place, so give it your own configuration. I just ran the exact same code with a dummy XML file and it worked perfectly with no exceptions or errors. Look up how to configure it yourself or what the default should be, and that could fix your problem.
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes