Everything works fine while my ide is open, but when i build my project it's not working as jar file. I guess the problem is at the path of my resource, I can't find any way to handle this problem, please help me if you have any solution.
public void playSound(String filename){
String strFilename = filename;
try {
ClassLoader classLoader = getClass().getClassLoader();
soundFile = new File(classLoader.getResource(strFilename).getFile());
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
You cannot address a resource in your jar as a File. In your IDE it likely is a file in the file system, not a resource in a jar. You need to be able to read the content as a URL and/or InputStream.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments