gpt4 book ai didi

kotlin - Mapbox:错误设置属性:icon-image [2]分支标签必须是数字或字符串

转载 作者:行者123 更新时间:2023-12-02 13:43:56 26 4
gpt4 key购买 nike

我正在尝试将Mapbox的Android SDK 9.0.0中的match() Expression与ID列表结合使用。但是在运行时出现以下错误:

"Error setting property: icon-image [2] Branch labels must be numbers or strings."



我在 Kotlin中编码。

为了找出问题的实质,我尝试使用 arrayOf()运算符将match()传递给单个String元素的数组:
match(get(KEY_ID), literal(arrayOf("134")), appearanceIfSelected, appearanceIfNotSelected)

上面的代码无法正常工作,并给出了上面的错误。使用 arrayListOf()的以下代码也失败:
match(get(KEY_ID), literal(arrayListOf(pois!!.first().id)), appearanceIfSelected, appearanceIfNotSelected)
listOf()也失败:
match(get(KEY_ID), literal(listOf(pois!!.first().id)), appearanceIfSelected, appearanceIfNotSelected)

包装 array() 也失败:
match(get(KEY_ID), array(literal(listOf("134"))), appearanceIfSelected, appearanceIfNotSelected)

我一直用 literal()包装,因为以下代码甚至无法编译:
match(get(KEY_ID), arrayOf("134"), appearanceIfSelected, appearanceIfNotSelected)

最佳答案

解决方法是,我将match()替换为 any() ,并使用 Kotlin spread operator "*" 传递了可变数量的参数

val eqPOIIdExpressions = arrayOf(eq(get(KEY_ID), "134"))

// The * operator below converts the Array<Expression> into varargs for any
// see https://proandroiddev.com/kotlins-vararg-and-spread-operator-4200c07d65e1

switchCase(
any(*eqPOIIdExpressions), appearanceIfSelected,
appearanceIfNotSelected
)

一旦完成该工作,便继续添加所有数组元素:
val eqPOIIdExpressions = pois!!.map {
eq(get(KEY_ID), it.id)
}.toTypedArray()

关于kotlin - Mapbox:错误设置属性:icon-image [2]分支标签必须是数字或字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60838614/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com