user859593
user859593

Reputation: 612

NullPointerException when using setCurrentMinute(Integer currentMinute) from TimePicker

    public void onTimeChanged(TimePicker tp, int hour, int min){
        tp.setOnTimeChangedListener(null);
        Integer a = new Integer(5);
        if(a == null){
            Log.d("ff", "integer IS null");
        } else {
            Log.d("ff", "integer is NOT null");
        }
        if(tp == null){
            Log.d("ff", "tp IS null");
        } else {
            Log.d("ff", "tp is NOT null");
        }
        tp.setCurrentMinute(a);
        tp.setOnTimeChangedListener(this);
    }

This is my TimePicker#OnTimeChangedListener. tp.setCurrentMinute(a) causes a NullPointerException. I've tried using an int and an Integer - neither works. tp is not null and a isn't either. Works just fine on emulator, but not on phone running 2.2.

Upvotes: 0

Views: 493

Answers (1)

guido
guido

Reputation: 19194

From the documentation:

public void setOnTimeChangedListener (TimePicker.OnTimeChangedListener onTimeChangedListener)
Since: API Level 1

Set the callback that indicates the time has been adjusted by the user.

Parameters
onTimeChangedListener the callback, should not be null.

You are setting the listener to null, then when you invoke .setCurrentMinute(a) the TimePicker gives a NullPointerException while trying to notify a null listener

Upvotes: 2

Related Questions