将聊天发送给其他人时出错。
java.lang.IllegalArgumentException: Response must include generic type (e.g., Response<String>)
for method APIService.sendnotif
at retrofit2.Utils.methodError(Utils.java:54)
at retrofit2.Utils.methodError(Utils.java:43)
at retrofit2.HttpServiceMethod.parseAnnotations(HttpServiceMethod.java:77)
at retrofit2.ServiceMethod.parseAnnotations(ServiceMethod.java:39)
at retrofit2.Retrofit.loadServiceMethod(Retrofit.java:202)
at retrofit2.Retrofit$1.invoke(Retrofit.java:160)
at java.lang.reflect.Proxy.invoke(Proxy.java:1006)
at $Proxy0.sendnotif(Unknown Source)
at com.azizah.msocial.ChatAct$7.onDataChange(ChatAct.java:297)
类接口ApiService
public interface APIService {
@Headers({
"Content-Type:application/json",
"Authorization:key=Lhghhkvhvhffgv"
})
@POST("fcm/send")
Call<Response> sendnotif(@Body Pengirim body);
}
sendnotif.class
apiService.sendnotif行中的错误
必须在此处包括通用类型。您能告诉我进行通用类型的改装吗?
private void sendnotif(final String hisUid, final String name, final String pesan) {
DatabaseReference alltoken = FirebaseDatabase.getInstance().getReference("Tokens");
Query query = alltoken.orderByKey().equalTo(hisUid);
query.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for(DataSnapshot ds: dataSnapshot.getChildren()){
Tokenclass tokenclass = ds.getValue(Tokenclass.class);
Datanotif data = new Datanotif(myUid, name+":"+pesan, "Pesan Baru", hisUid, R.drawable.ic_usr_name);
Pengirim pengirim = new Pengirim(data, tokenclass.getToken());
apiService.sendnotif(pengirim)
.enqueue(new Callback<Response>() {
@Override
public void onResponse(Call<Response> call, Response<Response> response) {
Toast.makeText(ChatAct.this, ""+response.message(), Toast.LENGTH_SHORT).show();
}
@Override
public void onFailure(Call<Response> call, Throwable t) {
}
});
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
apiService.sendnotif(pengirim)中的错误
请帮助我,这将使应用程序强制关闭
最佳答案
我的问题解决了,我在代码中弄错了
@Override
public void onResponse(Call<Response> call, Response<Response> response) {
Toast.makeText(ChatAct.this, ""+response.message(), Toast.LENGTH_SHORT).show();
}
将Call替换为Call,因为名为Respon not Response的类。