Seekbar handler Null Exception

In the mainactivity I have create a handler as instance variable: SeekBar seek_bar; MediaPlayer player; Handler seekHandler = new Handler(); Then I have the following two methods in the MainActivity to update the seekbar as the audio plays in media player: public void getInit() { seek_bar = (SeekBar) findViewById(R.id.seek_bar); } Runnable run = new Runnable() { @Override public void run() { seekUpdation(); **//Exception comes here while closing the app** } }; public void seekUpdation() { seek_bar.setProgress(mMediaPlayer.getCurrentPosition()); seekHandler.postDelayed(run, 1000); } The problem I am facing is that when the audio is running and user closes the application using device back buttton. I get NullPointerException. The destroy method of activity is: @Override protected void onDestroy() { super.onDestroy(); if (mMediaPlayer != null && mMediaPlayer.isPlaying()) { mMediaPlayer.stop(); mMediaPlayer.release(); mMediaPlayer = null; } }

以上就是Seekbar handler Null Exception的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏