blue-sky
blue-sky

Reputation: 53916

Uncaught exception: no application instance (blackberry)

Im trying to play an audio file using blackberry. This line - clickplayer.realize(); is throwing an exception - "Uncaught exception: no application instance". I'm not sure why this is being thrown ?

        UiApplication.getUiApplication().invokeLater(new Runnable() {
            public void run() {
                AudioPlayback a = new AudioPlayback();
                a.play();
            }
        });

This is the AudioPlayback class -

public class AudioPlayback {

    public void play(){

        try {
        Player clickplayer = null;
        InputStream instream = getClass().getResourceAsStream("/jingle.wav");
        clickplayer = Manager.createPlayer(instream, "audio/x-wav");
        clickplayer.realize();
        clickplayer.setLoopCount(1);

        VolumeControl vc = (VolumeControl) clickplayer.getControl("VolumeControl"); 
        if (vc != null)
            vc.setLevel(100);

        clickplayer.prefetch();
        clickplayer.setMediaTime(0);
        clickplayer.start();
        }
        catch(Exception e){
            e.printStackTrace();
        }

}

Upvotes: 0

Views: 952

Answers (1)

blue-sky
blue-sky

Reputation: 53916

Turns out I needed to register the event dispatcher before trying to play a sound. Below code fixes the issue where Driver is my own class that extends UiApplication.

Driver theApp = new Driver();
theApp.enterEventDispatcher();

Upvotes: 1

Related Questions