-1

I'm getting a FileNotFoundException when it's obviously right there. Just look at my screenshot: enter image description here

Does anyone know what's going on?

Entity1037
  • 81
  • 1
  • 9
  • 3
    "Obviously" not. My guess is that the relative path is not being resolved as you're assuming. Try making that path absolute and work backwards. – duffymo May 04 '15 at 22:31
  • 1
    try using src/ before the path, or move the file to the root project directory. should work. – previouslyactualname May 04 '15 at 22:32
  • Your problem sounds similar to http://stackoverflow.com/questions/4789325/android-path-to-asset-txt-file – nullPointer May 04 '15 at 22:32
  • 1
    You are using relative path. Try printing absolute path of current location `System.out.println(new File(".").getAbsolutePath());` and see if your relative path could be placed directly inside it to create valid path to your file. – Pshemo May 04 '15 at 22:33

3 Answers3

0

Resources (like your soundfile) shouldn't be in the sourcefolder, but in a separate resources folder. Apart from that: just look at the absolute path of your file, and you might notice it's not the path you think it is.

0

The answer is that FileInputStream starts at the project folder, and not src. Thank you Soham A! Also thank you Paul for letting me know that resources shouldn't be in the source folder.

Entity1037
  • 81
  • 1
  • 9
0

The patch to your file is src/sounds/... and you search in sounds/... (if your start directory is the project root, which it is by default), this is "obviously" wrong. BTW: I generally recommend you work with new FileInputStream(new File(relName).getAbsoluteFile()) (or similar), because then your exception will actually tell you where it was looking for the file.

Besides it looks like you want to load the resources as resources from the class loader.

eckes
  • 10,103
  • 1
  • 59
  • 71