带有 RxKotlinFX 堆栈的 Kotlin 给出 Cannot access class 错误

标签 kotlin rx-kotlin

当我在 pom 文件中使用以下依赖项时:

<properties>
    <rxkotlinfx.version>2.2.0</rxkotlinfx.version>
    <rxkotlin.version>2.1.0</rxkotlin.version>
    <kotlin.version>1.1.51</kotlin.version>
    <tornadofx.version>1.7.12</tornadofx.version>
</properties>

<dependencies>
    <dependency>
        <groupId>com.github.thomasnield</groupId>
        <artifactId>rxkotlinfx</artifactId>
        <version>${rxkotlinfx.version}</version>
    </dependency>
    <dependency>
        <groupId>io.reactivex.rxjava2</groupId>
        <artifactId>rxkotlin</artifactId>
        <version>${rxkotlin.version}</version>
    </dependency>
    <dependency>
        <groupId>no.tornado</groupId>
        <artifactId>tornadofx</artifactId>
        <version>${tornadofx.version}</version>
    </dependency>
    <dependency>
        <groupId>org.jetbrains.kotlin</groupId>
        <artifactId>kotlin-stdlib</artifactId>
        <version>${kotlin.version}</version>
    </dependency>
    <dependency>
        <groupId>org.jetbrains.kotlin</groupId>
        <artifactId>kotlin-test</artifactId>
        <version>${kotlin.version}</version>
        <scope>test</scope>
    </dependency>
</dependencies>

并运行以下代码:

fun main(args: Array<String>) {
    val source = listOf("A", "B", "C").toObservable()
            .filter { it == "B" }
            .subscribeBy(
                    onNext = { println(it) }
            )
}

我收到以下错误:

Error:(37, 40) Kotlin: Cannot access class 'io.reactivex.Observable'. Check your module classpath for missing or conflicting dependencies

为什么我会收到此错误以及我需要什么依赖项设置才能使用此堆栈?

最佳答案

我发现的唯一解决方案是显式依赖:

<dependency>
    <groupId>io.reactivex.rxjava2</groupId>
    <artifactId>rxjava</artifactId>
    <version>2.1.3</version>
</dependency>

关于带有 RxKotlinFX 堆栈的 Kotlin 给出 Cannot access class 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47187808/

相关文章:

java - 如何创建一个计时器来从 Activity 更新 TextView,并且当应用程序进入后台时它会继续运行

kotlin - Kotlin callInPlace 合约有哪些好处?

android - Rx Kotlin : map function can't infer return type

stream - 使用WebFlux的响应zip文件

android - AndThen 在可完成完成之前执行

swift - 我们如何在 kotlin mutlplatform 中处理 ios 和 android 平台的 api 响应?

android-studio - Kotlin + Gradle Unresolved reference

android - 'return' 不会跳出 Kotlin 中的 forEach

android - 如何在 android 中处理 rxjava 链中的错误?

android - 如何将此 rxjava/rxkotlin flatMap 转换为 lambda 表达式?