0
我是一個小白程序設計師,我遇到了一個問題,我有一個mediaplayer.start()
內的onClick
方法,如果我叫如何停止MediaPlayer onPause()如果我在onButtonClick方法中聲明/啓動它?
mediaplayer.stop();
mediaplayer.reset();
mediaplayer.release();
它會崩潰,出現錯誤:
Attempt to invoke virtual method 'void android.media.MediaPlayer.stop()' on a null object reference ".
我試過How to stop the mediaplayer playing from other methods但是當我使用它時,我得到了:
"Unable to destroy activity {...Activity}: java.lang.IllegalStateException"
任何支持都非常感謝
你開始聲音還有'mediaplayer'變量,請定義你能後的線路?只需編輯您的問題以包含代碼。 – ByteHamster
它最終奏效了我剛宣佈的mediaplayer全球和公衆,ty! –
我認爲你已經將它定義爲公開的:D無論如何,很高興聽到它現在起作用! :) – ByteHamster