Android Studio 3.4.1,Kotlin“未解决的参考:mutableListOf" [英] Android Studio 3.4.1, Kotlin "unresolved reference: mutableListOf"

查看:204
本文介绍了Android Studio 3.4.1,Kotlin“未解决的参考:mutableListOf"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Android Studio 3.4.1中使用Kotlin构建AAR,并且得到了可怕的未解决参考".我尝试使用mutableListOf时出错.

I am building an AAR with Kotlin in Android Studio 3.4.1, and I get the dreaded "unresolved reference" error when I try to use mutableListOf.

 val myBuffer: mutableListOf<Byte>()

在撰写本文时,我已将Kotlin更新为最新版本

I updated Kotlin to the latest version at the time of writing

在build.gradle中,还统一定义了Kotlin版本.

In build.gradle, the Kotlin version is also consistently defined.

在build.gradle模块中,使用了以下插件:

In the module build.gradle, the following plugins are used:

apply plugin: 'com.android.library'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

据我了解,Kotlin语言插件(包括集合类)应自动包含在Android Studio中.无论如何,我正在使用其他Kotlin类,例如ByteArray,没有问题.

I understood from what I read, that the Kotlin language plugin, including collection classes, should be automatically included in Android Studio. In any case, I'm using other Kotlin classes, e.g. ByteArray, without a problem.

根据我在网上找到的建议,我进行了清理和重建,还选择了File |使高速缓存无效/重新启动并重新构建.这没用;引用仍未解决.

Following advice that I found online, I cleaned and re-built, also selected File | Invalidate Caches/Restart and re-built. It did not work; the reference is still unresolved.

Kotlin文档没有说此功能已被弃用,这是我发现的另一个可能原因.

The Kotlin documentation doesn't say that this function is deprecated, which was another possible cause that I found.

我想念什么?

推荐答案

您犯了一些拼写错误:使用 = 而不是::

You have made some typo error: use = and not ::

 val myBuffer = mutableListOf<Byte>()

或明确指定类型:

 val myBuffer: MutableList<Byte> = mutableListOf<>()

这篇关于Android Studio 3.4.1,Kotlin“未解决的参考:mutableListOf"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆