Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

Error:(13, 5) error: method does not override or implement a method from a supertype in Weather app

Seems to be a bit of a clunky start to the asynchronous section of the weather app. I initially couldn't get any of the AlertDialogFragment code to populate via IntelliJ as indicated in the videos. I then noticed that the instructor had 4 additional imports that I did not have and had not been mentioned up to this point in the course. I then added in the following and I could get some of it to work.

import android.app.Dialog;
import android.app.DialogFragment;
import android.content.Context;
import android.os.Bundle;

I still could not get OnCreateDialog to come up via intelliJ so I manually typed everything out which resulted in the following.

@Override
    public Dialog OnCreateDialog(Bundle savedInstanceState){
        Context context = getActivity();
        AlertDialog.Builder builder = new AlertDialog.Builder(context)
                .setTitle(R.string.error_title)
                .setMessage(R.string.error_message)
                .setPositiveButton(R.string.error_ok_button_text, null);
        AlertDialog dialog = builder.create();
        return dialog;
    }

After this, @Override showed an error and the code will not run. The error is the one from the title of this post.

Also worth mentioning, the automatic add to string resources doesn't work in my version of Android studio as it does for Ben in the video. Compare my code from above for the build parameters to what the video shows.

In the video, you will see that "context" is part of the line for each string resource add. Why is this different?

Android Studio difference?

I am not sure what I need to do to proceed with my application as I'm not sure how to resolve the error or tell Android Studio how to use the appropriate 'Dialog' class, provided that is even what the issue is.

Please advise.

If I take the @Override out, it will then run, but no error dialog ever displays.

3 Answers

Remove the initial capital from OnCreateDialog, I think.

It should be onCreateDialog.

Steve.

I recalled helping someone else wth a very similar problem so tracked down that response ... same issue here. That was a year ago - I clearly need to get out more. ;-)

https://teamtreehouse.com/community/override-throws-method-does-not-override-method-from-its-superclass-error

Hi Bob,

You seem to be having some issues! Let's see if we can sort that.

Firstly, are you using Android Studio and is it kitted out with the updated Android SDK etc?

The error you're pointing out seems to be some inheritance issue - the @Override isn't seeing a superclass. In my code, the class header looks like:

public class AlertDialogFragment extends DialogFragment

So there's a superclass of a Dialog type there. Does your code have something similar?

Try adding the following to your imports (although these should update with the Organise Imports key strokes).

import android.app.AlertDialog;

I agree that there's a difference with the string handling too - my code has context.getString(R.string.stringName) rather than a straight reference to the resource as in yours. I suspect this is a related issue, so let's focus on the superclass problem first, then narrow the issues from there.

Steve.

Thank you for the reply, Steve.

Here is my entire AlertDialogFragment class

import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.Context;
import android.os.Bundle;

/**
 * Created by Bob on 10/21/2015.
 */
public class AlertDialogFragment extends DialogFragment {
    @Override
    public Dialog OnCreateDialog(Bundle savedInstanceState){
        Context context = getActivity();
        AlertDialog.Builder builder = new AlertDialog.Builder(context)
                .setTitle(R.string.error_title)
                .setMessage(R.string.error_message)
                .setPositiveButton(R.string.error_ok_button_text, null);
        AlertDialog dialog = builder.create();
        return dialog;
    }
}

Thank you, Steve! That has resolved (this) issue. :)

Glad it worked - is there another thread for your other issue(s)?

Steve.