1

I got problem about play wav file in my application.

This is my error:

java.lang.IllegalArgumentException
 at javax.microedition.media.Manager.createPlayer(), bci=8
 at Tajwid.Tajwid.run(Tajwid.java:649)
 at Tajwid.Tajwid.actionPerformed(Tajwid.java:186)
 at com.sun.lwuit.util.EventDispatcher.fireActionSync(), bci=19
 at com.sun.lwuit.util.EventDispatcher.fireActionEvent(EventDispatcher.java:257)

This is my code:

public void run() {
    try {
        InputStream is = getClass().getResourceAsStream("/tes.wav");
        player = Manager.createPlayer(is, "audio/x-wav");

        player.realize();
        // get volume control for player and set volume to max
        vc = (VolumeControl) player.getControl("VolumeControl");
        if (vc != null) {
            vc.setLevel(100);
        }
        player.prefetch();
        player.start();
    } catch (Exception e) {
        e.printStackTrace();
    }

Device Configuration : CLDC-1.1
Device Profile MIDP 2.0

gnat
  • 6,213
  • 108
  • 53
  • 73
Paijo S Kom
  • 61
  • 1
  • 6
  • 3
    What is your problem? Did you get an exception? – Telmo Pimentel Mota Jul 12 '12 at 19:11
  • My wav file can't play, what's wrong? – Paijo S Kom Jul 13 '12 at 13:07
  • 1
    As your code seems right and assuming you did not get an exception. I think the problem is with your file or with your device (it might not play wav). Please call System.getProperty("audio.encodings") and see what you can play. – Telmo Pimentel Mota Jul 13 '12 at 14:24
  • 1
    This is my error : java.lang.IllegalArgumentException at javax.microedition.media.Manager.createPlayer(), bci=8 at Tajwid.Tajwid.run(Tajwid.java:649) at Tajwid.Tajwid.actionPerformed(Tajwid.java:186) at com.sun.lwuit.util.EventDispatcher.fireActionSync(), bci=19 at com.sun.lwuit.util.EventDispatcher.fireActionEvent(EventDispatcher.java:257) – Paijo S Kom Jul 14 '12 at 16:47

1 Answers1

1

Error message you've got has sufficient information to figure what went wrong in the code.

Look at it a bit closer:

    java.lang.IllegalArgumentException
     at javax.microedition.media.Manager.createPlayer()...

It says something went wrong in Manager.createPlayer(). From your code, it is apparent that you use method Manager.createPlayer(java.io.InputStream stream, java.lang.String type).

If you look into API documentation for the method you use (available online), you'll find the explanation when this exception occurs:

    Throws:
        java.lang.IllegalArgumentException - Thrown if stream is null. 

Above means that stream parameter (is in your code) passed to the method is null.

You could add some logging right after initialization of the is to debug this issue easier:

InputStream is = getClass().getResourceAsStream("/tes.wav");
// add some logging to see if initialization was OK or not:
System.out.println("input stream is null: [" + (is == null) + "]");

That way, when running your MIDlet in emulator, you will see whether is was initialized as expected or not.

Actually, looking at the code I would guess that you made a typo in file name passed to getResourceAsStream: "/tes.wav" looks like a mis-typed "/test.wav".

gnat
  • 6,213
  • 108
  • 53
  • 73
  • @MuhamadBurhanudin you are welcome. In case if you're interested, you may take a look at [instructions explaining how does accepting an answer work at Stack Overflow](http://meta.stackexchange.com/a/5235/165773) – gnat Jul 16 '12 at 08:03
  • 1
    I got answer problem, check here : [link]http://burhanudin.web.id/programing/java/play-audio-with-j2me[/link] – Paijo S Kom Jul 29 '12 at 00:55