除了判断player是否等于null,还要判断isplaying,否者报错
public
void run() { // TODO Auto-generated method stub boolean isTrue=true; while(isTrue=true){ try{ Thread.sleep(1000); }catch(InterruptedException e){ e.printStackTrace(); } if(player==null){ isTrue=false; }else{ if(player.isPlaying()){//这是插入的代码 int position=player.getCurrentPosition(); Message msg=handler.obtainMessage(); msg.what=position; handler.sendEmptyMessage(position); } } }