Can’t override onCreateDialog method of

When I try to override the onCreateDialog method of I get the following error: ‘onCreateDialog overrides nothing’.

According to I should be able to override it as it’s defined as open.

I am using the following code

import android.content.DialogInterface
import android.os.Bundle

class MyDialogFragment : DialogFragment() {

    override fun onCreateDialog(savedInstanceState: Bundle): Dialog {
        return activity?.let {
            val builder = AlertDialog.Builder(it)
            builder.setMessage("Yes or no?")
                    DialogInterface.OnClickListener { dialog, id ->
                        // yes
                    DialogInterface.OnClickListener { dialog, id ->
                        // no
        } ?: throw IllegalStateException("Activity cannot be null")

What’s going on here?


If you look closely at the method signature you will see that the parameter is marked with the @Nullable, and its type is Bundle?.

onCreateDialog(@Nullable savedInstanceState: Bundle?)

But in your case you have defined the type of parameter as Bundle which is non nullable, making your function signature different than the one you are trying to override hence the error