Unchecked call to method as a member of raw type

19,541

Looks like you have to declare your T type too, in your case it has to be a class of response.body() instance.

Try to replace line

public static void getOpenWeatherData(String city, String appId, IWeatherCallbackListener listener)

to

public static void getOpenWeatherData(String city, String appId, IWeatherCallbackListener<ResponseBody> listener)

That is so because when you declare your interface

IWeatherCallbackListener<T>

You use T and its raw type. When you create instance you have to show what exactly type you will use or what exactly type you want to receive as argument.

For example if you create that listener manually that had to look like this

IWeatherCallbackListener<ResponseBody> listener = new IWeatherCallbackListener<ResponseBody>() {
    //implementation of methods
}

Same thing for arguments, you have to show what T you can receive.

Share:
19,541
Akash Bisariya
Author by

Akash Bisariya

I am an Android Developer. Programming is good!!! Programming is life!!! Read My Blog - https://bigakash.blogspot.com/ Github Profile - https://github.com/akash-bisariya About Me - https://about.me/akash_bisariya

Updated on July 25, 2022

Comments

  • Akash Bisariya
    Akash Bisariya almost 2 years

    Following warning is shown in my project -

    Unchecked call to 'getWeatherData(T,Boolean,String)' as a member of raw type 'IWeatherCallbackListener'.

    I have created following interface -

    public interface IWeatherCallbackListener<T> {
     void getWeatherData(T weatherModel, Boolean success, String errorMsg);
    }
    

    And called it in following way,

    public class WeatherConditions {
    
    private static IWeatherApi mWeatherApi;
    
    /**
     * @param city
     * @param appId
     * @param listener
     */
    public static void getOpenWeatherData(String city, String appId, IWeatherCallbackListener listener) {
    
        mWeatherApi = ApiService.getRetrofitInstance(BASE_URL_OPEN_WEATHER).create(IWeatherApi.class);
        Call<OpenWeatherModel> resForgotPasswordCall = mWeatherApi.getOpenWeatherData(appId, city);
        resForgotPasswordCall.enqueue(new Callback<OpenWeatherModel>() {
            @Override
            public void onResponse(Call<OpenWeatherModel> call, Response<OpenWeatherModel> response) {
                if (response.body() != null) {
                    if (listener != null)
                        listener.getWeatherData(response.body(), true, "");
                }
            }
    
            @Override
            public void onFailure(Call<OpenWeatherModel> call, Throwable t) {
                if (listener != null)
                     listener.getWeatherData(null, false, t.getMessage());
            }
        });
    }
    

    I have implemented this interface in my MainActivity and called the method as -

    WeatherConditions.getOpenWeatherData(etCityName.getText().toString(), OPEN_WEATHER_APP_ID, MainActivity.this)
    

    Can anyone please help and explain this warning.

  • Akash Bisariya
    Akash Bisariya over 6 years
    thanks @DEADMC your solution is working perfectly fine, but can you please explain it because I did not understand this concept.It would be a great help.