I have attempted about everything I have seen regarding this issue on stackoverflow but can't seem to correctly retrieve an xml file using the .getClass method. I am continuing to get a null pointer exception but can't figure out why. I have tried several variations. If I am doing anything wrong please let me know. Also, if you require any additional information just ask :D. Here are some of the variations I have tried
URL configURL = new URL("" + Transcriber.class.getClass().getClassLoader().getResourceAsStream("/config.xml"));
ConfigurationManager cm = new ConfigurationManager(configURL);
URL configURL = new URL("" + Transcriber.class.getClass().getClassLoader().getResource("/config.xml"));
ConfigurationManager cm = new ConfigurationManager(configURL);
InputStream configURL = Transcriber.class.getClass().getClassLoader().getResourceAsStream("/config.xml");
ConfigurationManager cm = new ConfigurationManager(configURL.toString());
I should also note that when using eclipse I am able to retrieve the xml. However, when converted to an executable jar I cannot.
EDIT:
URL configURL = new URL("" + Transcriber.class.getResourceAsStream("config.xml"));
Console output =
Exception in thread "main" java.net.MalformedURLException: no protocol: java.io.BufferedInputStream@238be9f2
at java.net.URL.<init>(Unknown Source)
at java.net.URL.<init>(Unknown Source)
at java.net.URL.<init>(Unknown Source)
at speechcapture.Transcriber.main(Transcriber.java:53)