[英]java.lang.IllegalArgumentException: Response must include generic type (e.g., Response<String>)
Error when I send a chat to others.向其他人发送聊天时出错。
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)
class interface ApiService class接口ApiService
public interface APIService {
@Headers({
"Content-Type:application/json",
"Authorization:key=Lhghhkvhvhffgv"
})
@POST("fcm/send")
Call<Response> sendnotif(@Body Pengirim body);
}
sendnotif.class ERROR in line apiService.sendnotif must include generic type in here. apiService.sendnotif 行中的 sendnotif.class 错误必须在此处包含泛型类型。 can u explain to me to make generic type retrofit?你能向我解释一下制作通用类型 retrofit 吗?
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) {
}
});
}
error in apiService.sendnotif(pengirim) apiService.sendnotif(pengirim) 中的错误
please help me, It makes app force close请帮助我,它使应用程序强制关闭
my problem solved, I make mistake in the code我的问题解决了,我在代码中犯了错误
@Override
public void onResponse(Call<Response> call, Response<Response> response) {
Toast.makeText(ChatAct.this, ""+response.message(), Toast.LENGTH_SHORT).show();
}
Call replace to Call because the class named Respon not Response.调用替换为调用,因为 class 命名为响应而不是响应。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.