I am having Overload Resolution Ambiguity error in this line:

departureHourChoice!!.selectionModel.select(currentHourIndex)

For Reference:

  • departureHourChoiceChoiceBox<Int>,从java.scene.control开始

  • currentHourIndex is an Int

  • 重载解决模糊性发生在.select()方法中;它是重载的,可以接受两种参数:(T obj)(int index).

  • The .select() method allows for an item in a ChoiceBox to be selected, and you can determine which one can be selected by referencing to that item or to it's index. In this case, I want it to be selected by Index (int).

  • 这是一张错误enter image description here的照片

如何解决超负荷解决歧义?

推荐答案

It seems that you are hit by this bug as a workaround you can :

  • currentHourIndex号框:

    lateinit var departureHourChoice: ChoiceBox<Int>
    ...
    val currentHourIndex = 1
    departureHourChoice.selectionModel.select(currentHourIndex as Int?)
    
  • 或者将ChoiceBox的声明改为java.lang.Integer,而不是Kotlin的Int:

    lateinit var departureHourChoice: ChoiceBox<java.lang.Integer>
    ...
    val currentHourIndex = 1
    departureHourChoice.selectionModel.select(currentHourIndex)
    

进一步阅读:

Kotlin相关问答推荐

我如何测试一个可组合组件没有显示,但如果它不存在也接受?

Kotlin中函数引用的否定

新的jOOQ Gradle插件无法正确处理自引用关系

如何让 LocalDateTime.parse 拒绝 24:00 时间

如何在数据类中删除空格 (String)?

Kotlin 复制列表中的项目以创建具有相同数据的不同对象的新列表

用于将 0.5 变为 0 的 round() 函数的模拟

如何访问嵌套在另一个 map 中的 map 中的值(在 kotlin 中)

Kotlin 中的as Long和.toLong()有什么区别?

Kotlin 条件格式字符串

Picasso 回调

有没有办法重用 Job 实例?

为什么 android studio 不为所有安全参数生成代码?

哪里可以找到aapt2日志(log)?

@uncheckedVariance 在 Kotlin 中?

Jetpack Compose – LazyColumn 不重组

Kotlin:sealed class cannot "contain" data classes?

main函数和常规函数有什么区别?

如何在Kotlin中将字符串转换为InputStream?

具有多个 parameter的 Kotlin 枚举