向其他人发送聊天时出错。
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)中的错误
请帮助我,它使应用程序强制关闭
2条答案
按热度按时间x6492ojm1#
这个改动,fix了问题,是proguard导致的问题,增加了一行proguard规则
https://github.com/square/retrofit/pull/3910/files/9831d5c3f9d28c61d29078d89645bce8ea258366#diff-50d428633d98e235831f5f9b75d7aa48897d5edc2bed30c55c9bb9ec20b36f82
e0bqpujr2#
我的问题解决了,我在代码中犯了错误
调用替换为调用,因为类名为Respon而不是Response。