我正在尝试通过变量来完成URL,但是当我将其传递并将其添加到要连接的URL时,它给我一个错误
override fun onCreate
var mparam = intent.getStringExtra("param")
interface ApiActaPartido {
@GET("My_url"+$mparam)
fun getActaPartido(): Call<ActaPartidoList>
}
Error:(84, 77) Expecting an element Error:(84, 14) An annotation parameter must be a compile-time constant
请帮忙。
最佳答案
An annotation parameter must be a compile-time constant
这是在告诉您,编译器需要在编译时知道您在注释中使用的值。由于您正在动态获取该变量的值(
var mparam = intent.getStringExtra("param")
),因此无法将该值编译为要为其构建的字节码中。您将必须找到一种方法来使
@GET
使用的值成为编译时常量,或者使用另一种方法来完成打算提供的任何功能。
关于variables - 使用Kotlin的URL变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48024043/