Home > database >  Callback error, which class to import? chat app
Callback error, which class to import? chat app

Time:04-15

I'm creating a chat app and I imported this 3-year-old project so a lot of things have changed, especially this thing that I can't fix, Android studio advises me to import a class to fix this error only that many come out and I don't know which one to choose ?

Gives me the error on Callback on 10 line - (Cannot resolve symbol 'Callback')

public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
            for (DataSnapshot snapshot : dataSnapshot.getChildren()){
                Token token = snapshot.getValue(Token.class);
                Data data = new Data(fuser.getUid(), R.mipmap.ic_launcher, username ": " message, "New Message",
                        userid);

                Sender sender = new Sender(data, token.getToken());

                apiService.sendNotification(sender)
                        .enqueue(new Callback<MyResponse>() {
                            @Override
                            public void onResponse(Call<MyResponse> call, Response<MyResponse> response) {
                                if (response.code() == 200){
                                    if (response.body().success != 1){
                                        Toast.makeText(MessageActivity.this, "Failed!", Toast.LENGTH_SHORT).show();
                                    }
                                }
                            }

                            @Override
                            public void onFailure(Call<MyResponse> call, Throwable t) {

                            }
                        });
            }
        }

CodePudding user response:

It seems like you are looking for the retrofit2 package. I suspect you will need to import Call and Response from this package as well. Depending on where else this module is used, you may need to import additional classes from this package. Try adding the following lines:

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
  • Related