I programmed an app that displays images and plays sounds. That's why it needs to load images and sounds from a folder called "recources" that is located in the src folder of the project.
For the images I'm using the following code to load the png and then display it on my frame:
ImageIcon img = new ImageIcon(getClass().getResource("/recources/img.png"));
That works fine for running the app inside Netbeans and also after I built it into a jar.
The sounds are being loaded like that:
public Sound(){
try
{
File audiodata = new File("/recources/audio.wav");
if(audiodata.exists()){
audioInput = AudioSystem.getAudioInputStream(audiodata);
clip= AudioSystem.getClip();
clip.open(audioInput);
clip.start();
}
}
catch(Exception e){
e.printStackTrace();
}
}
That also works inside Netbeans but does not in the finished jar. --> NullPointerException
What do I need to change in my code?
What also doesnt work:
I also want to load a sqllite database with a jdbc driver with this code:
public void getConnection() {
try {
Class.forName("org.sqlite.JDBC");
} catch (ClassNotFoundException ex) {
Logger.getLogger(Lagerverwaltung.class.getName()).log(Level.SEVERE, null, ex);
}
try {
Connection con = DriverManager.getConnection("jdbc:sqlite:recources/database.db");
} catch (SQLException ex) {
Logger.getLogger(Lagerverwaltung.class.getName()).log(Level.SEVERE, null, ex);
}
}
It has the same issue, when I run it in Netbeans it finds the database but in the built jar its not found.
I added the resources folder as a source to the properties of my project.