views:

29

answers:

1

I am making a midlet which is to be used to play out local audio files. It is obviously not working. I am getting a null reference on the "is" variable, in the code snippet shown below.

1. try{
2. System.out.println("path: " + this.getClass());
3. InputStream is = this.getClass().getResourceAsStream("res/01Track.wav");
4. p1=Manager.createPlayer(is, "audio");
5. p1.realize();            
6. p1.prefetch();
7. p1.start();
8. }
9. catch(Exception e){
10. System.out.println(e.getMessage());
11. }

I assume there is something wrong with the "this.getClass().getResourceAsStream("res/01Track.wav")" bit, but I can not for the life of me figure out why, and I have tried referring to the file in 20 different ways.

If I printline "this.getClass()" it gives me "path: class Mp3spiller". The absolute path to "01Track.wav" is "E:\Mine dokumenter\Dokumenter\workspace_mobiljava\Mp3spiller\res\01Track.wav". Am I completely wrong in thinking that I should refer relatively to "E:\Mine dokumenter\Dokumenter\workspace_mobiljava\Mp3spiller"?

If anyone could point out what I am doing wrong, I would be grateful. I have basically stolen the code from a tutorial I found online, so I would have thought it would be working.

A: 

Hi,

the player initialization is wrong... second parameter takes the mime type for the stream you are playing. hence it should be

p1=Manager.createPlayer(is, "audio/wav");

otherwise everything seems ok... if you have added the resouce folder according to the Vivart's last comment.

hope this helps...

Vijay C