I'm creating a method that is supposed to find the path to a text file and return it as a String to be used for a configuration file. Here's the block of code that is being affected:
public String getConfigLocation() {
String fileName = "locateconfig.txt";
ClassLoader classLoader = ClassLoader.getSystemClassLoader();
File file = new File(classLoader.getResource(fileName).getFile());
locationFile = file.getAbsolutePath();
return locationFile;
}
The line that's causing this exception to be thrown is File file = new File(classLoader.getResource(fileName).getFile());
.
Here's the first few lines of the stack trace - just the first few, because all the methods being affected here interact with the one I'm having a problem with.
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at epicorexpert.EpicoreJFrame.getConfigLocation(EpicoreJFrame.java:1068)
at epicorexpert.EpicoreJFrame.checkConfig(EpicoreJFrame.java:1076)
at epicorexpert.EpicoreJFrame.<init>(EpicoreJFrame.java:94)
What probably-obvious issue am I overlooking? Thanks.
Edit: Why is this being marked as a duplicate question and suggesting a redirect for the thread on what NullPointerExceptions are? I understand what they are and how they're typically resolved. That's not what I'm asking here; this is specifically about the ClassLoader and File objects and why I'm getting NPEs from them.