Cephon
Cephon

Reputation: 41

FileNotFoundException: Playing an mp3 file with Java/Eclipse

I am trying to play an mp3 using an external mp3 library and everything is fine until it comes to finding the file.

I have imported the file into eclipse as seen in the below image. My workspace

And here is my error:

enProblem playing file mpthreetest.mp3
java.io.FileNotFoundException: mpthreetest.mp3 (The system cannot find the file   specified)
java.lang.NullPointerException

Any help would be appreciated.

Upvotes: 0

Views: 660

Answers (3)

cigno5.5
cigno5.5

Reputation: 712

You cannot find your file because you're trying to access it by a relative path. But probably you aren't considering that a package, at runtime, is NOT a directory.

So, if you try to look for a file by new File("myfile") the JVM assume you're starting from the "root" of your application (usually the working dir).

To solve this situation you can put the mp3 file in root package or by referring to it via absolute path.

Upvotes: 0

TheMonkWhoSoldHisCode
TheMonkWhoSoldHisCode

Reputation: 2332

Try giving the absolute path of the file and see if that works.

Upvotes: 0

robermann
robermann

Reputation: 1722

Check the current execution dir: new java.io.File(".").getAbsolutePath() will tell you.

Upvotes: 1

Related Questions