简体   繁体   English

java.lang.IllegalArgumentException:响应必须包括泛型类型(例如,响应<string> )</string>

[英]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.

相关问题 java.lang.IllegalArgumentException:FormUrlEncoded 只能在带有请求正文的 HTTP 方法上指定(例如,@POST) - java.lang.IllegalArgumentException: FormUrlEncoded can only be specified on HTTP methods with request body (e.g., @POST) java.lang.IllegalArgumentException:无法添加到layout:约束必须是字符串 - java.lang.IllegalArgumentException: cannot add to layout: constraint must be a string java.lang.IllegalArgumentException: HTTP 方法注释是必需的(例如,@GET、@POST 等)。尝试调用apiInterface GET 请求时出错 - java.lang.IllegalArgumentException: HTTP method annotation is required (e.g., @GET, @POST, etc.).Error when trying call apiInterface GET request java.lang.IllegalArgumentException:地图大小(0)必须&gt; = 1 - java.lang.IllegalArgumentException: Map size (0) must be >= 1 java.lang.IllegalArgumentException:方法不能为null - java.lang.IllegalArgumentException: Method must not be null java.lang.IllegalArgumentException:上下文不得为null - java.lang.IllegalArgumentException: Context must not be null java.lang.IllegalArgumentException:必须为StyledEditorKit - java.lang.IllegalArgumentException: Must be StyledEditorKit java.lang.IllegalArgumentException:目标不能为空 - java.lang.IllegalArgumentException: Target must not be null java.lang.IllegalArgumentException:字符串数组上的参数类型不匹配 - java.lang.IllegalArgumentException: argument type mismatch on string array Retrofit2错误:Java.lang.IllegalArgumentException:URL查询字符串“ a = {action}&type = json&key = 15670403”必须没有替换块 - Retrofit2 error : Java.lang.IllegalArgumentException: URL query string “a={action}&type=json&key=15670403” must not have replace block
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM