【问题标题】:java.lang.IllegalArgumentException: Response must include generic type (e.g., Response<String>)java.lang.IllegalArgumentException:响应必须包含泛型类型(例如,Response<String>)
【发布时间】:2020-06-14 15:39:16
【问题描述】:

向其他人发送聊天时出错。

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) 中的错误

请帮帮我,它会使应用程序强制关闭

【问题讨论】:

  • 你能告诉我们这个 Response 和 Pengirim 类是什么吗?

标签: java android firebase retrofit2


【解决方案1】:

我的问题解决了,我在代码中出错了

@Override
public void onResponse(Call<Response> call, Response<Response> response) {
Toast.makeText(ChatAct.this, ""+response.message(), Toast.LENGTH_SHORT).show();
 }

调用 replace 为 Call,因为名为 Respon 的类不是 Response。

【讨论】:

    猜你喜欢
    • 2015-08-25
    • 1970-01-01
    • 1970-01-01
    • 2018-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多