TimePicker getCurrentHour() and getCurrentMinute() not working in Android-Collection of common programming errors

I’ve followed this tutorial http://developer.android.com/resources/tutorials/views/hello-timepicker.html to create a time picker, I then created a second one and I’m attempting to compare the difference between the two. I have the following method and for some reason getCurrentHour() and getCurrentMinute() are not working even though they have been imported as public methods. Here is my method:

private void calcShiftLength() {
int difHour = mTimeDisplayEnd.getCurrentHour() -mTimeDisplay.getCurrentHour();
int difMin = mTimeDisplayEnd.getCurrentMinute() - mTimeDisplay.getCurrentMinute();

mShiftLength.setText(new StringBuilder().append(difHour).append(":").append(difMin));
}

I get the following error code “The method getCurrentHour() is undefined for the type TextView” Thanks for any help. Edit:I realised some of the method was set up for testing the error, which I understand the issue I’m just unsure how to resolve it. Here is an exmaple of my TimePicker’s being used:

private TimePickerDialog.OnTimeSetListener mTimeSetListener = new     TimePickerDialog.OnTimeSetListener() {
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
        mHour = hourOfDay;
        mMinute = minute;
        updateDisplay();
    }
};
private TimePickerDialog.OnTimeSetListener mTimeSetListenerEnd = new TimePickerDialog.OnTimeSetListener() {
    public void onTimeSet(TimePicker view2, int hourOfDay, int minute) {
        mHour = hourOfDay;
        mMinute = minute;
        updateDisplayEnd();
    }
};

Edit2: Here’s my declarations:

    private TextView mShiftLength;

private TextView mTimeDisplay;
private Button mPickTime;

private TextView mTimeDisplayEnd;
private Button mPickTimeEnd;

private int mHour;
private int mMinute;

static final int TIME_DIALOG_ID = 0;
static final int TIME_DIALOG_IDEND = TIME_DIALOG_ID + 1;

Edit 3: The following code is meant to convert the hours to an int and then take them away to calculate the difference. I will work with the 24 hour time later I just want to have it working for now. Anyway it is crashing my app at the moment:

    private void calcShiftLength() {
    int startTime = Integer.parseInt(mTimeDisplay.getText().toString());
    int endTime = Integer.parseInt(mTimeDisplayEnd.getText().toString());
    int shiftLength = endTime - startTime;

    mShiftLength.setText(new StringBuilder().append(shiftLength));
}
  1. getCurrentHour() method can only be used with widget type TimePicker. Please confirm if your are using correct widget. The error clearly says you are trying access it using TextView instead.

Originally posted 2014-02-03 02:28:05.