无法访问内置声明确保您依赖于 Kotlin 标准库

KES*_*MAR 5 intellij-idea kotlin

错误:(11, 40) Kotlin:无法访问内置声明“kotlin.coroutines.SuspendFunction1”。确保您依赖于 Kotlin 标准库

fun Route.coroutineHandler(fn: suspend (RoutingContext) -> Unit) {
    handler { ctx ->
        launch(ctx.vertx().dispatcher()) {
            try {
                fn(ctx)
            } catch (e: Exception) {
                ctx.fail(e)
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

Fal*_*ger 2

就像Slaw评论的那样,只需将依赖项添加到您的项目中,如自述文件kotlinx-coroutines-core中所述

梅文

添加依赖项(您还可以添加您需要的其他模块):

<dependency>
    <groupId>org.jetbrains.kotlinx</groupId>
    <artifactId>kotlinx-coroutines-core</artifactId>
    <version>1.3.5</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

并确保您使用最新的 Kotlin 版本:

<properties>
    <kotlin.version>1.3.70</kotlin.version>
</properties>
Run Code Online (Sandbox Code Playgroud)

摇篮

添加依赖项(您还可以添加您需要的其他模块):

dependencies {
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.5'
}
Run Code Online (Sandbox Code Playgroud)

并确保您使用最新的 Kotlin 版本:

buildscript {
    ext.kotlin_version = '1.3.70'
}
Run Code Online (Sandbox Code Playgroud)

确保您有jcenter()mavenCentral()在存储库列表中:

repository {
    jcenter()
}
Run Code Online (Sandbox Code Playgroud)