【问题标题】:Unresolved reference currentThread().wait() with kotlin in Android Studio在 Android Studio 中使用 kotlin 未解决的参考 currentThread().wait()
【发布时间】:2017-02-10 12:09:38
【问题描述】:

我和here 有同样的问题。我想应用已接受的答案。但我无法做到这一点,因为 IDE 在该行中声明:

 Thread.currentThread().wait();

“wait”是一个未解决的引用。我在 Android Studio 中使用 kotlin,所以可能是 kotlin 插件导致了问题。在 Preferences 的插件部分中声明我安装了 1.0.6-release-Studio2.2-1 kotlin 版本。而在项目 build.gradle 中:

buildscript {
ext.kotlin_version = '1.0.6'
repositories {
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:2.2.3'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    classpath "io.realm:realm-gradle-plugin:2.3.0"

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}

如果我将 kotlin_version 更改为 1.0.6-release-Studio2.2-1 Ide 指出Kotlin version that is used for building with Gradle (1.0.6-release-Studio2.2-1) differs from the one bundled into the IDE plugin (1.0.6)

所以我的第一个问题是如何处理未解决的引用错误。 第二个:是否有其他/更好的方法来强制 IntentService 等到 DownloadManager 完成下载并按照this 问题中的要求调用 onReceive()。

【问题讨论】:

    标签: android


    【解决方案1】:

    请查看页面中间某处的https://kotlinlang.org/docs/reference/java-interop.html

    Effective Java Item 69 建议优先使用并发实用程序而不是 wait() 和 notify()。因此,这些方法不适用于 Any 类型的引用。如果你真的需要给他们打电话,你可以投到java.lang.Object:(foo as java.lang.Object).wait()

    【讨论】:

      猜你喜欢
      • 2019-01-08
      • 1970-01-01
      • 1970-01-01
      • 2023-01-17
      • 2021-11-02
      • 1970-01-01
      • 2019-10-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多