Java 无法为2创建呼叫适配器。响应<;okhttp3.响应库>;

Java 无法为2创建呼叫适配器。响应<;okhttp3.响应库>;,java,android,firebase,Java,Android,Firebase,我正在尝试向google的FCM服务器发送一个POST请求,这样我就可以订阅特定的主题并发送/接收消息 下面我还使用了RxJava3为我的改装设置了呼叫适配器。我不熟悉这些功能,我想我缺少了一些东西。我不确定。我应该更改API的返回类型还是更改调用适配器?感谢您的帮助 EXCEPTION IN LOGCAT : Unable to create call adapter for retrofit2.Response<okhttp3.ResponseBody> MainActivit

我正在尝试向google的FCM服务器发送一个POST请求,这样我就可以订阅特定的主题并发送/接收消息

下面我还使用了
RxJava3
为我的改装设置了呼叫适配器。我不熟悉这些功能,我想我缺少了一些东西。我不确定。我应该更改API的返回类型还是更改调用适配器?感谢您的帮助

EXCEPTION IN LOGCAT : Unable to create call adapter for retrofit2.Response<okhttp3.ResponseBody>
MainActivity.java

package com.deepesh.myfcmapp;

import androidx.appcompat.app.AppCompatActivity;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import com.google.firebase.messaging.FirebaseMessaging;
import com.google.gson.Gson;
import okhttp3.ResponseBody;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava3.RxJava3CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;


public class MainActivity extends AppCompatActivity {

    public static final String FCM_CHANNEL_ID = "fcm_channel_id";
    private static final String TAG = "TAG";
    EditText title_editText, message_editText, token_editText;
    Button send_button;
    Retrofit retrofit1;
    NotificationAPI notificationAPI;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        FirebaseMessaging.getInstance().subscribeToTopic(MyConstants.TOPIC);

        init();

        // CREATE NOTIFICATION CHANNEL
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            NotificationChannel fcm_channel = new NotificationChannel(FCM_CHANNEL_ID, "FCM channel", NotificationManager.IMPORTANCE_HIGH);
            NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
            manager.createNotificationChannel(fcm_channel);
        }


    }


    void init() {
        title_editText = findViewById(R.id.title_editText);
        token_editText = findViewById(R.id.token_editText);
        message_editText = findViewById(R.id.message_editText);
        send_button = findViewById(R.id.send_button);
        send_button.setOnClickListener(clickListener);
    }


    void sendNotififcation(PushNotification pushnotification) {

        retrofit1 = new Retrofit.Builder()
                .addConverterFactory(GsonConverterFactory.create())
                .baseUrl(MyConstants.BASE_URL)
                //IMP
                .addCallAdapterFactory(RxJava3CallAdapterFactory.create())
                .build();

        notificationAPI = retrofit1.create(NotificationAPI.class);

        try {
            Response<ResponseBody> response = notificationAPI.postNotification(pushnotification);

            if (response.isSuccessful()) {
                Log.d(TAG, "RESPONSE : " + new Gson().toJson(response));
            } else {
                Log.d(TAG, "ERROR : " + response.errorBody());
            }

        } catch (Exception e) {
            Log.d(TAG, "EXCEPTION : " + e.getMessage());
        }

    }

    View.OnClickListener clickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            String title = title_editText.getText().toString();
            String message = message_editText.getText().toString();

            if (!title.isEmpty() && !message.isEmpty()) {

                PushNotification pushNotification = new PushNotification(MyConstants.TOPIC, new NotififcationData(title, message));
                sendNotififcation(pushNotification);

            }

        }
    };

}
NotificationData.java

package com.deepesh.myfcmapp;

public class NotififcationData {

    String title;
    String message;

    public NotififcationData(String title, String message) {
        this.title = title;
        this.message = message;
    }
    
}
PushNotification.java

package com.deepesh.myfcmapp;

public class PushNotification {

// variable names should be same as in the formats

    String to;
    NotififcationData data;

    public PushNotification(String to, NotififcationData data) {
        this.to = to;
        this.data = data;
    }
}
NotificationAPI.java

package com.deepesh.myfcmapp;

import okhttp3.ResponseBody;
import retrofit2.Response;
import retrofit2.http.Body;
import retrofit2.http.Headers;
import retrofit2.http.POST;

public interface NotificationAPI {


    @Headers({"Authorization: key="+ MyConstants.SERVER_KEY,"Content-Type:"+ MyConstants.CONTENT_TYPE} )
    @POST("fcm/send")
    Response<ResponseBody> postNotification(@Body PushNotification pushNotification);

}
package com.deepesh.myfcmapp;
进口okhttp3.0响应电子书;
2.回应;;
导入文件2.http.Body;
导入2.http.Headers;
导入文件2.http.POST;
公共接口通知API{
@标题({“Authorization:key=“+MyConstants.SERVER\u key”,内容类型:“+MyConstants.Content\u Type})
@邮政(“fcm/发送”)
响应postNotification(@Body PushNotification PushNotification);
}

如果您遇到问题,最好在发布问题时创建一个问题列表。您为此问题发布了近300行代码。对于人们来说,在线解析和调试是非常困难的。请编辑您的问题并隔离问题,这样可以增加您获得帮助的机会。
package com.deepesh.myfcmapp;

public class PushNotification {

// variable names should be same as in the formats

    String to;
    NotififcationData data;

    public PushNotification(String to, NotififcationData data) {
        this.to = to;
        this.data = data;
    }
}
package com.deepesh.myfcmapp;

import okhttp3.ResponseBody;
import retrofit2.Response;
import retrofit2.http.Body;
import retrofit2.http.Headers;
import retrofit2.http.POST;

public interface NotificationAPI {


    @Headers({"Authorization: key="+ MyConstants.SERVER_KEY,"Content-Type:"+ MyConstants.CONTENT_TYPE} )
    @POST("fcm/send")
    Response<ResponseBody> postNotification(@Body PushNotification pushNotification);

}