0

我正在尝试跟踪 Steam URL 播放的历史记录,以及 getCurrentPosition 的值,以使用户能够恢复他们在该会话期间中断的视频。我的策略是使用两个 Arraylist 来存储数据、比较 URL 并通过 Intent Extras 将之前的位置填回去。

我在调用我的 getter 时收到 NPE。以下是重要部分:

Getter/Setter 类:

public class WatchedGS {

private ArrayList videoURL = new ArrayList();
private ArrayList resumeTime = new ArrayList();

public ArrayList getURL() {
return videoURL;
}

public void setURL(String videoURL) {
    this.videoURL.add(videoURL);
    Log.i("videoURL added: ", videoURL);
}

public ArrayList getresumeTime() {
    return resumeTime;
}

public void setresumeTime(int time) {
    this.resumeTime.add(time);
    Log.i("videoTime added: ", ""+ time);
}
}

媒体播放器调用设置在表面销毁,确认工作:

    public void surfaceDestroyed(SurfaceHolder holder) {
    watchedGS.setURL(urlString);
    watchedGS.setresumeTime(player.getCurrentPosition());
    player.release();
    player = null;
    finish();
}

MainActivity调用get,导致NPE:

    WatchedGS historyList;

            if (videoHistory){
            int alSize = historyList.getURL().size();
            if (historyList.getURL().contains(url)) {
                Log.i("it's there!", url);
            }

我确定我忽略了一些愚蠢的事情,并且会感谢我错过的任何指示。先感谢您。

4

1 回答 1

1
WatchedGS historyList;

        if (videoHistory){
        int alSize = historyList.getURL().size();
        if (historyList.getURL().contains(url)) {
            Log.i("it's there!", url);
        }

historyList在调用它之前你没有初始化getURL()

于 2013-07-23T16:48:28.387 回答