注释参数必须是一个编译时间常数-Kotlin

发布于 2025-02-03 06:38:25 字数 833 浏览 1 评论 0原文

我想在我的主动脉上从覆盖功能中发送一个参数,以在接口上使用,以每次我单击下拉列表时都会更改URL。

On my MainActivity i have:

before the class definition:

var item2:String="popular"
class MainActivity : AppCompatActivity(),AdapterView.OnItemClickListener {

on the same activity:

    override fun onItemClick(parent: AdapterView<*>?, view: View?, position: Int, id: Long)
{
    val item = parent?.getItemAtPosition(position).toString()
    item2=item

} 

and in the interface:

val get_url:String ="/3/movie/$item2?api_key=KEY_NUMBER"
interface MovieApiInterface {
    @GET(get_url)
    fun getMovieList(): Call<MovieResponse>

}

But there i have "An annotation argument must be a compile-time constant"

Don't understand why :(

Thanks

I wanna send an argument from an override function on my MainActivity to use on an interface to changue an URL everytime that i made click on a drop down list.

On my MainActivity i have:

before the class definition:

var item2:String="popular"
class MainActivity : AppCompatActivity(),AdapterView.OnItemClickListener {

on the same activity:

    override fun onItemClick(parent: AdapterView<*>?, view: View?, position: Int, id: Long)
{
    val item = parent?.getItemAtPosition(position).toString()
    item2=item

} 

and in the interface:

val get_url:String ="/3/movie/$item2?api_key=KEY_NUMBER"
interface MovieApiInterface {
    @GET(get_url)
    fun getMovieList(): Call<MovieResponse>

}

But there i have "An annotation argument must be a compile-time constant"

Don't understand why :(

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱你不解释 2025-02-10 06:38:25

错误消息实际上是描述性的,您只能将编译时常数作为参数传递给注释,因此您需要替换

val get_url:String ="/3/movie/$item2?api_key=KEY_NUMBER"
interface MovieApiInterface {
    @GET(get_url)
    fun getMovieList(): Call<MovieResponse>

}

interface MovieApiInterface {
    @GET("/3/movie/$item2?api_key=KEY_NUMBER")
    fun getMovieList(): Call<MovieResponse>

}

The error message is actually pretty descriptive, you can only pass compile-time constants as arguments to annotations, so you'll need to replace:

val get_url:String ="/3/movie/$item2?api_key=KEY_NUMBER"
interface MovieApiInterface {
    @GET(get_url)
    fun getMovieList(): Call<MovieResponse>

}

with:

interface MovieApiInterface {
    @GET("/3/movie/$item2?api_key=KEY_NUMBER")
    fun getMovieList(): Call<MovieResponse>

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文