从RxJava编译示例时找不到org.reactivestreams.Publisher的类文件?

Dim*_*ims 1 java maven rx-java rx-java2

以下代码

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);
   }

}
Run Code Online (Sandbox Code Playgroud)

导致以下编译错误

错误:(9、15)Java:无法访问org.reactivestreams.Publisher的org.reactivestreams.Publisher类文件

POM依赖关系如下

<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>
Run Code Online (Sandbox Code Playgroud)

Iva*_*ovk 5

相同的错误和简单的解决方案-将其添加到您的应用Gradle文件

implementation 'io.reactivex.rxjava2:rxjava:2.1.14'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'
Run Code Online (Sandbox Code Playgroud)


小智 4

我也遇到了同样的情况,已经解决了 添加依赖如下:

<dependency>
    <groupId>org.reactivestreams</groupId>
    <artifactId>reactive-streams</artifactId>
    <version>1.0.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)