2011-05-03 32 views
0

我試圖播放使用黑莓的音頻文件。 這一行 - clickplayer.realize();拋出一個異常 - 「未捕獲的異常:沒有應用程序實例」。我不知道爲什麼這會被拋出?未捕獲的異常:沒有應用程序實例(黑莓)

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

這是AudioPlayback類 -

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(); 
     } 

} 

回答

1

原來我需要嘗試播放聲音之前註冊事件調度。下面的代碼修復了驅動程序是我自己的擴展UiApplication類的問題。

Driver theApp = new Driver(); 
theApp.enterEventDispatcher(); 
相關問題