Click here to Skip to main content
15,867,488 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I HAVE ERROR IN

listener.onFetchData(response.body().getArticles(),response.message());
warning: [unchecked] unchecked call to onFetchData(List,String) as a member of the raw type OnFetchDataListener


Java
public void getNewsHeadlines(OnFetchDataListener listener, String category, String query) {
    CallNewsApi callNewsApi = retrofit.create(CallNewsApi.class);
    Call<NewsApiResponse> call = callNewsApi.callHeadlines("ma", category, query, context.getString(R.string.api_key));

    try {
      call.enqueue(new Callback<NewsApiResponse>() {
        @Override
        public void onResponse(@NonNull Call<NewsApiResponse> call, @NonNull Response<NewsApiResponse> response) {
          if (!response.isSuccessful()) {
            Toast.makeText(context, "Error!!", Toast.LENGTH_SHORT).show();
          }
          assert response.body() != null;

          //// here error //////
          listener.onFetchData(response.body().getArticles(), response.message());

        }

        @Override
        public void onFailure(@NonNull Call<NewsApiResponse> call, @NonNull Throwable t) {
          listener.onError("Request Failed!");

        }
      });


What I have tried:

Java
listener.onFetchData(response.body().getArticles(),response.message());
Posted
Updated 8-Aug-22 7:23am
v2

The compiler cannot check whether the return data is in the correct form or not, so it issues this warning. Try adding checkable types for the result data thus:
Java
List<String> articles = response.body().getArticles();
String msg = response.message();
listener.onFetchData(articles, msg);
 
Share this answer
 
Comments
Youssef Nassiri 8-Aug-22 13:42pm    
did not work
I need TO Call to onFetchData
how do that
Richard MacCutchan 9-Aug-22 3:11am    
Sorry, you need to go to the documentation for the CallNewsApi class, that should explain how to use it correctly.
The warning is saying that you are using the method onFetchData of the listener type: OnFetchDataListener without declaring the type of data it's listening for. I think OnFetchDataListener is a templated type. The warning is stating that the compiler is unable to check that onFetchData will return the type of data you want because you are declaring listener to be a raw (untemplated) OnFetchDataListener.

My guess would be that OnFetchDataListener wants to retrieve a list of things like: ArrayList<string> or List<newsarticle> (if NewsArticle were a defined type or class object).

I think the declaration of the method getNewsHeadlines should be changed to something like the following:
public void getNewsHeadlines(OnFetchDataListener<List<String>> listener, String category, String query)


I'm not sure exactly what the template parameters for OnFetchDataListener should be. You'll have to go back into your code to determine that yourself.
 
Share this answer
 
Comments
Youssef Nassiri 8-Aug-22 13:52pm    
did not work
I need TO Call to onFetchData
how do that
if you want to help me
I Sending you images in email / SENT TO ME MESSAG AND I SEND YOU photo
youssefnassiri822@gmail.com
PLAES I need the help

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900