当前位置: 代码迷 >> Android >> MP3项目,播放完就报错?解决方案
  详细解决方案

MP3项目,播放完就报错?解决方案

热度:99   发布时间:2016-05-01 21:02:33.0
MP3项目,播放完就报错?
问题:播放完就报错。报错代码(PlayerService.java:152)是:message = (String) messages.poll(); 

log:

06-08 08:49:10.527: D/dalvikvm(22098): GC_EXTERNAL_ALLOC freed 126K, 51% free 2638K/5379K, external 2081K/2137K, paused 71ms
06-08 08:52:30.068: D/AndroidRuntime(22098): Shutting down VM
06-08 08:52:30.068: W/dalvikvm(22098): threadid=1: thread exiting with uncaught exception (group=0x40015560)
06-08 08:52:30.120: E/AndroidRuntime(22098): FATAL EXCEPTION: main
06-08 08:52:30.120: E/AndroidRuntime(22098): java.lang.NullPointerException
06-08 08:52:30.120: E/AndroidRuntime(22098): at napo.mp3player.service.PlayerService$UpdateTimeCallback.run(PlayerService.java:152)
06-08 08:52:30.120: E/AndroidRuntime(22098): at android.os.Handler.handleCallback(Handler.java:587)
06-08 08:52:30.120: E/AndroidRuntime(22098): at android.os.Handler.dispatchMessage(Handler.java:92)
06-08 08:52:30.120: E/AndroidRuntime(22098): at android.os.Looper.loop(Looper.java:123)
06-08 08:52:30.120: E/AndroidRuntime(22098): at android.app.ActivityThread.main(ActivityThread.java:3683)
06-08 08:52:30.120: E/AndroidRuntime(22098): at java.lang.reflect.Method.invokeNative(Native Method)
06-08 08:52:30.120: E/AndroidRuntime(22098): at java.lang.reflect.Method.invoke(Method.java:507)
06-08 08:52:30.120: E/AndroidRuntime(22098): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
06-08 08:52:30.120: E/AndroidRuntime(22098): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
06-08 08:52:30.120: E/AndroidRuntime(22098): at dalvik.system.NativeStart.main(Native Method)
06-08 08:57:30.247: I/Process(22098): Sending signal. PID: 22098 SIG: 9

相关代码:
public void run() {
// 计算偏移量
long offset = System.currentTimeMillis() - begin;
if (currentTimeMill == 0) {
nextTimeMill = (Long) times.poll();
message = (String) messages.poll();
}
if (offset >= nextTimeMill) {
Intent intent = new Intent();
intent.setAction(AppConstant.LRC_MESSAGE_ACTION);
intent.putExtra("lrcMessage", message);
sendBroadcast(intent);
message = (String) messages.poll();
nextTimeMill = (Long) times.poll();
}
currentTimeMill = currentTimeMill + 10;
handler.postDelayed(updateTimeCallback, 10);

------解决方案--------------------
发文件:PlayerService.java上来
------解决方案--------------------
这个代码和之前的出错提示对不上号,发最新的出错提示以及最新的代码上来。
------解决方案--------------------

nextTimeMill = (Long) times.poll();
前面加一段
 if(times != null)
------解决方案--------------------
有2个地方都要加if(times != null)噢

探讨

不行啊,播完之后错误还是和刚才一样

------解决方案--------------------
package napo.mp3player.service;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Queue;

import napo.lrc.LrcProcessor;
import napo.model.Mp3Info;
import napo.mp3player.AppConstant;
import android.app.Service;
import android.content.Intent;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Environment;
import android.os.Handler;
import android.os.IBinder;

public class PlayerService extends Service {
 private boolean isPlaying = false;
 private boolean isReleased = false;
 private MediaPlayer mediaPlayer = null;

 private ArrayList<Queue> queues = null;
  相关解决方案