Search code examples
androiddatepickerdialog

Unable to implement DatePickerDialog on Android


I'm using this library, and I'm following what it says.

I've added this implementation to my class:

implements com.wdullaer.materialdatetimepicker.date.DatePickerDialog.OnDateSetListener

And this method:

@Override
public void onDateSet(DatePickerDialog view, int year, int monthOfYear, int dayOfMonth) {
    String date = "You picked the following date: "+dayOfMonth+"/"+(monthOfYear+1)+"/"+year;
}

But for some reason I get the error:

Class 'xxxx' must be either declared abstract or implement abstract method 'onDateSet(..)

I've also seen the sample, and I've done the same thing it does there.


Solution

  • When you get an error message like that, but you've already got a method with the given name, it usually means that the signature is wrong. In this case, it's pretty much gotta be that the DatePickerDialog type for the first parameter is the wrong one, since ints are ints everywhere.

    If your IDE auto-imported a DatePickerDialog class, it probably chose android.app.DatePickerDialog. That interface, though, is expecting com.wdullaer.materialdatetimepicker.date.DatePickerDialog. You can either use the fully-qualified class name in the method signature, or just change your import statement to point to the correct class.