Java.lang.ClassNotFoundException: Class io.reactivex.functio



我正在使用rxjava版本v-2.2.6 & naiksoftware/stompprotocolandroid v-1.6.4

我不断收到此错误

java.lang.ClassNotFoundException: Class io.reactivex.functions.Action not found   

每当我添加此库实现时

'com.github.NaikSoftware:StompProtocolAndroid:1.5.2'到我的build.gradle文件,为什么会这样?

public void connectStomp(View view) {
    List<StompHeader> headers = new ArrayList<>();
    headers.add(new StompHeader(LOGIN, "guest"));
    headers.add(new StompHeader(PASSCODE, "guest"));
    //mStompClient.withClientHeartbeat(10000).withServerHeartbeat(10000);
    resetSubscriptions();
    Disposable dispLifecycle = mStompClient.lifecycle()
    .subscribeOn(Schedulers.io())
    .observeOn(AndroidSchedulers.mainThread())
    .subscribe(lifecycleEvent -> {
    switch (lifecycleEvent.getType()) {
    case OPENED:
    Log.e(TAG, "Stomp connection opened");
    //toast("Stomp connection opened");
    break;
    case ERROR:
    Log.e(TAG, "Stomp connection error", lifecycleEvent.getException());
    //toast("Stomp connection error");
    mStompClient.reconnect();
    break;
    case CLOSED:
    Log.e(TAG, "Stomp connection closed");
    mStompClient.disconnect();
    resetSubscriptions();
    //toast("Stomp connection closed");
    // mStompClient.connect();
    break;
    case FAILED_SERVER_HEARTBEAT:
    Log.e(TAG, "Stomp connection opened");
    //toast("Stomp failed server heartbeat");
    break;
    }
    }, throwable -> {
    Log.e(TAG, "Error on subscribe topic", throwable);
    });
    compositeDisposable.add(dispLifecycle);
    // Receive greetings
    Disposable dispTopic = mStompClient.topic("/topic/greetings")
    .subscribeOn(Schedulers.io())
    .observeOn(AndroidSchedulers.mainThread())
    .subscribe(topicMessage -> {
    Log.d(TAG, "Received " + topicMessage.getPayload());
    //addItem(mGson.fromJson(topicMessage.getPayload(), EchoModel.class));
    }, throwable -> {
    Log.e(TAG, "Error on subscribe topic", throwable);
    });
    compositeDisposable.add(dispTopic);
    mStompClient.connect(headers);
}

NaikSoftware/StompProtocolAndroid库没有使用更新的代码,我在Android中集成stomp客户端时遇到了类似的问题。

请参阅下面的存储库以获取解决方案,将服务器 url 和端口号替换为自定义端口和服务器 url。

回购- https://github.com/NaikSoftware/StompProtocolAndroid

让我知道它是否解决了您的问题。

最新更新