class file for org.reactivestreams.Publisher not found while compiling example from RxJava?
Asked Answered
A

3

7

The following code

package com.inthemoon.snippets.rxjava;

import io.reactivex.*;

public class HelloWorld {

   public static void main(String[] args) {
      Flowable.just("Hello world").subscribe(System.out::println);
   }

}

causes the following compile error

Error:(9, 15) java: cannot access org.reactivestreams.Publisher class file for org.reactivestreams.Publisher not found

POM dependency is following

<dependencies>
        <!-- https://mvnrepository.com/artifact/io.reactivex.rxjava2/rxjava -->
        <dependency>
            <groupId>io.reactivex.rxjava2</groupId>
            <artifactId>rxjava</artifactId>
            <version>2.0.4</version>
        </dependency>


    </dependencies>
Anjelicaanjou answered 24/1, 2017 at 8:53 Comment(3)
have you tried adding reactive-streams explicitly to your maven dependencies ?Nescience
Yes, now tried. It works either with .final explicit or iv RxJava 2.0.3Anjelicaanjou
The same dependency 2.0.4 works fine for me ... maybe get rid of the dependency and do a -U to force updating dependencies .. then adding the 2.0.4 again ...Nescience
I
15

Same error and simple solution - add this to your app Gradle file

implementation 'io.reactivex.rxjava2:rxjava:2.1.14'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'
Internecine answered 19/6, 2019 at 9:44 Comment(4)
Perfect! Thank you. rxjava was missing from my gradle.Baez
It is strange as I have a project 8 month old where just a second line (second import) was enough to work well and the new project has issue similar to topic starter.Yeung
Got a though this dependency migh went implicitly with some other dependency in that first projectYeung
While adding kotlinx.coroutines.flow.Flow flow in room I got this error and after adding the above mentioned implementation, its fine, however how is Kotlinx Flow and rx are related in this caseRamsden
P
4

The same happened to me.I have solved it. add the dependeny follows:

<dependency>
    <groupId>org.reactivestreams</groupId>
    <artifactId>reactive-streams</artifactId>
    <version>1.0.0</version>
</dependency>
Premier answered 24/5, 2017 at 1:28 Comment(0)
G
4

This has been fixed since 2.0.5 by github.com/ReactiveX/RxJava/issues/5014 2.1.1, is the latest version as of this answer

Solution :

    <dependency>
        <groupId>io.reactivex.rxjava2</groupId>
        <artifactId>rxjava</artifactId>
        <version>2.1.1</version>
    </dependency>
Gavial answered 19/7, 2017 at 20:43 Comment(2)
adding some explanation would be really necessarySemblance
so editing your answer to improve it would be better than a comment.Semblance

© 2022 - 2024 — McMap. All rights reserved.