使用GSON @Body转换器对.Model.Sender类(参数#1)(参数#1)进行改造

时间:2019-03-18 08:57:09

标签: gson retrofit

我有2个应用程序,一个给客户,一个给驾驶员,当我按驱动程序中的通话按钮时,应用崩溃 错误是
  java.lang.IllegalArgumentException:无法为com.ddu.d_ride_customer.Model.Sender类创建@Body转换器(参数#1)         用于方法IFCMService.sendMessage

客户应用程序中的客户端

private static Retrofit retrofit = null;
public static Retrofit getClient(String baseURL)
{
    if(retrofit == null)
    {
        retrofit = new Retrofit.Builder()
                .baseUrl(baseURL)
               // .addConverterFactory(ScalarsConverterFactory.create())
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }
    return retrofit;
}

界面

public interface IFCMService {

    @Headers({
            "Content-Type:application/json",
            "Authorization:Key=AAAAF4ob75Y:APA91bEwOLl6608rdRMsDYyhV8Bd61wxWQYItrrmiinzDu-nUFqlbzdphqmMWahXz6cNLf5lFw44sIG49qWH9N-EHoyB38Hrx88DggodeGTW_RH43OLJOvOr7_Pg660DDMV6_kGEuSAx"

    })

    @POST("fcm/send")

    Call<FCMResponse> sendMessage(@Body Sender body);
}

按下按钮时会生成错误的Java类

private void sendRequestToDriver(String driverId) {


    DatabaseReference tokens = FirebaseDatabase.getInstance().getReference(Common.token_tbl);

    tokens.orderByKey().equalTo(driverId)
        .addListenerForSingleValueEvent(new ValueEventListener() {
            @Override
            public void onDataChange(@NonNull DataSnapshot dataSnapshot) {

                for (DataSnapshot postSnapshot : dataSnapshot.getChildren()) {
                    Token token = postSnapshot.getValue(Token.class);//

                    String json_lat_lng = new Gson().toJson(new LatLng(mlastlocation.getLatitude(), mlastlocation.getLongitude()));

                    Notification data = new Notification("D-ride", json_lat_lng);

                    Sender content = new Sender(token.getToken(), data);
                    //token.getToken(), data);

                    mService.sendMessage(content).enqueue(new Callback<FCMResponse>() {
                        @Override
                        public void onResponse(Call<FCMResponse> call, Response<FCMResponse> response) {

                            if (response.body() != null && response.body().success == 1)
                                Toast.makeText(Home.this, "Request sent!", Toast.LENGTH_SHORT).show();
                            else
                                Toast.makeText(Home.this, "Failed", Toast.LENGTH_SHORT).show();
                        }


                        @Override
                        public void onFailure(Call<FCMResponse> call, Throwable t) {
                            Log.e("ERROR", t.getMessage());
                        }
                    });

                }
            }

0 个答案:

没有答案