Hi all,
I've a problem with creating a jar file that's melting my brain. I've been at it for the last 3 days and cannot solve. I've tried pretty much everything. If anyone can help, please do.
So originally I had a File [] called soundFile that is going to store 9 files. I had a loop to import the 9 wav files. These wav files were called 0db.wav, 1db.wav etc etc and to get the code to work, I had to put these files inside my Version 4 folder (see image attached - Method 1 folder).
My original code for loading was as follows:
Code:
for (int i = 0; i < 9; i++){
soundFile [i] = new File (i + "db.wav");
}
This worked fine when I ran the project in NetBeans. However, a couple of days ago I tried to create the jar file and the section that played the sounds did not work i.e. did not play the sounds. From looking at it, when I told NetBeans to load the file it looked in the Version 4 folder (see image attached - Method 1 folder).
I then looked around everywhere to see what the problem was. I ended up getting the jar file working by hard-coding in a directory address but as you might guess, when I changed computer it stopped working.
So then after getting advice from other forums I tried numerous things. The most promising was to move the wav files into the rubberduckssoundproject folder which is inside the src folder. This folder rubberduckssoundproject contains all our other code in the project. The code for loading the wav files was then:
Code:
for (int i = 0; i < 9; i++){
try{
soundFile [i] = new File (this.getClass().getResource (i+"db.wav").toURI());
}
catch (Exception fileError){
System.out.println("Sorry but there's a problem loading your files into an array");
fileError.printStackTrace();
}
System.out.println("The soundfile located at soundFile "+i+" has the following path:"+soundFile[i].getAbsolutePath());
}
So this worked when the project was run in NetBeans. The path it returned for the files was ".........\Version 4\build\classes\rubberduckssoundproject\0db.wav"
This looked good to me as I think (I'm fairly new to
Java) the jar files gets built from the build folder???
However, now when I clean and build, a jar file gets created but when I go to click this jar nothing happens. Then when I go back into the project folder it will not let me delete the jar file. It keeps saying "The action can't be completed because the file is open in Java (TM) Platform SE binary. This leads me to believe there's some sort of infinite loop or something being created?
I've thought about creating InputStreams and passing them to the
Code:
audio = AudioSystem.getAudioInputStream(soundFile[activeSound]);
The problem with this is I need an array of InputStreams and NetBeans will not let me do this. Can't remember exactly why, but it wouldn't. If anyone needs to know what it said I can try it again.
Please, please, please help if you can. I'm on the verge of giving up and I really don't want to.
Thanks a mil.
Al.