Chad
Chad

Reputation: 50

Android - Null pointer calling Arraylist with getter/setter.

I am attempting to track history of steam URL's played, and the value of getCurrentPosition to offer the user the capability to resume a video where they had left off during that session. My strategy has been to use two Arraylists to stash the data, compare the URL and stuff the previous position back through the intent extras.

I receive an NPE on a call to my getter. Here are the important parts:

Getter/Setter class:

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);
}
}

Mediaplayer calling set on surface destroy, confirmed working:

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

MainActivity calling get, causing NPE:

    WatchedGS historyList;

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

I'm sure I've overlooked something silly, and would appreciate any pointers in what I've missed. Thank you in advance.

Upvotes: 0

Views: 308

Answers (1)

Bill the Lizard
Bill the Lizard

Reputation: 405745

WatchedGS historyList;

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

You're not initializing historyList before calling getURL() on it.

Upvotes: 1

Related Questions