I wrote this while following a video tutorial. The tutorial showed the same thing but got no error!
Here's the code:
public static void main(String[] args){
DocumentBuilderFactory bf = DocumentBuilderFactory.newInstance();
try {
DocumentBuilder db = bf.newDocumentBuilder();
//says input stream cannot be null
Document d = db.parse(XmlReader.class.getResourceAsStream("XMLFile.xml"));
d.normalize();
When I run the program, it says that the input stream cannot be null for the statement indicated statement but, its not null!. The file path is correct! Is there something I'm missing? Is there a problem with eclipse or XMLfiles or something?
Stack trace:
Exception in thread "main" java.lang.IllegalArgumentException: InputStream cannot be null
at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
at io.XMLFileReading.main(XMLFileReading.java:27)