A java project runs well from the command line, but it throws an exception when run from NetBeans

StackOverflow https://stackoverflow.com/questions/23237331

  •  08-07-2023
  •  | 
  •  

Frage

A Java NetBeans project runs successfully from from the java command line. However, when I try to run it in NetBeans I get the following error:

Exception in thread "main" java.io.FileNotFoundException: lost_in_euroland.wav (The system cannot find the file specified)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(FileInputStream.java:146)
    at com.sun.media.sound.WaveFloatFileReader.getAudioInputStream(WaveFloatFileReader.java:164)
    at javax.sound.sampled.AudioSystem.getAudioInputStream(AudioSystem.java:1179)
    at projtest.ProjTest.main(ProjTest.java:27)
Java Result: 1
BUILD SUCCESSFUL (total time: 1 second)

Perhaps the audio files are not at the right place. If it is so where they are to be placed?

War es hilfreich?

Lösung 2

File lost_in_euroland.wav not found which is at line (FileInputStream.java:146) its is because Netbean could not found the file specify. Try to test your path again and retry.

Suggestions:

In Netbeans when you read any file it start from Project path like C:\Users\pc\Documents\NetBeansProjects\MyCurrentProject. create a new folder or place your lost_in_euroland.wav file in project folder like

C:\Users\pc\Documents\NetBeansProjects\MyCurrentProject\lost_in_euroland.wav

OR

C:\Users\pc\Documents\NetBeansProjects\MyCurrentProject\sound\lost_in_euroland.wav

Andere Tipps

The most likely explanation for this error is that your filepath for lost_in_euroland.wavis incorrect. When running a program from the command line, the directory is defaulted to where you opened the shell from, whereas NetBeans (or any IDE, for that matter) does not default to a specified directory (perhaps C:/)

Instead of lost_in_euroland.wav, try to use the absolute filepath, which might look like C://Users//<Your Username>//Desktop//lost_in_euroland.wav (notice the double slashes to ensure that the filepath is correct in Netbeans - due to Java escape sequences).

Hope this helps!

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top