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 Build a Weather App (2015) Concurrency and Error Handling Handling Errors

saranyamoellers
saranyamoellers
31,691 Points

Please help "Method doesn't overide medthod from its superclass" I can't compile my weather api?

package com.example.stormy;

import android.app.AlertDialog;
import android.app.VoiceInteractor;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;

import java.io.IOException;

import javax.security.auth.callback.Callback;

import okhttp3.Call;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

public class MainActivity extends AppCompatActivity {
    public static final String TAG = MainActivity.class.getSimpleName();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //https://api.forecast.io/forecast/3fb2674b400dcf2d4a5c61dfcb88a658/37.8267,-122.423
        String apiKey = "3fb2674b400dcf2d4a5c61dfcb88a658";
        double latitude = 37.8267;
        double longitude = -122.423;
        String api = "https://api.forecast.io/forecast/" + apiKey +
                "/" + latitude + "," + longitude;
        OkHttpClient client = new OkHttpClient();
        Request request = new Request.Builder()
                .url(api)
                .build();
        Call call = client.newCall(request);
        call.enqueue(new Callback() {
            @Override
            public void onFailure(Request request, IOException e) {
                Log.e(TAG, "onRespone error"+ request.toString());
            }
            @Override
            public void onResponse(Response response) throws IOException {
                try {
                    if (response.isSuccessful()){
                        Log.v(TAG, response.body().string());}
                } catch (IOException e) {
                    Log.e(TAG, "............caught exception", e);
                }

            }
        });
        Log.e(TAG, "Main UI code is running!");

    }
}
saranyamoellers
saranyamoellers
31,691 Points

I have a red line under last two @override

1 Answer

Seth Kroger
Seth Kroger
56,413 Points

Unfortunately the class name Callback is a bit generic and many packages and libraries can have that class name. That means when you auto-import the class Android Studio may pick the wrong one like it did here. Luckily it's simple enough to fix.

// Change this line...
import javax.security.auth.callback.Callback;
// ...to this:
import okhttp3.Callback;
saranyamoellers
saranyamoellers
31,691 Points

Thank you very much for your time. I did like you said but still not working and Callback() also has a red line under it. Thanks Seth for trying to help.