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
Error message you've got has sufficient information to figure what went wrong in the code.
Look at it a bit closer:
It says something went wrong in
Manager.createPlayer(). From your code, it is apparent that you use methodManager.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:
Above means that
streamparameter (isin your code) passed to the method is null.You could add some logging right after initialization of the
isto debug this issue easier:That way, when running your MIDlet in emulator, you will see whether
iswas 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".