简体   繁体   English

Android Studio 显示此错误:Retrofit2 Android HTTP 方法注释是必需的(例如,@GET、@POST 等)

[英]Android Studio showing this error :Retrofit2 Android HTTP method annotation is required (e.g., @GET, @POST, etc.)

It keeps showing me this error in Android Studio, I am using retrofit 2, trying to get data from Yelp API and it keeps showing me this msg它一直在 Android Studio 中向我显示这个错误,我正在使用改造 2,试图从 Yelp API 获取数据,它一直向我显示这个消息

java.lang.RuntimeException: Unable to start activity ComponentInfo{sf.alomari.yelp/sf.alomari.view.MainActivity}: java.lang.IllegalArgumentException: HTTP method annotation is required (eg, @GET, @POST, etc.). java.lang.RuntimeException:无法启动活动 ComponentInfo{sf.alomari.yelp/sf.alomari.view.MainActivity}:java.lang.IllegalArgumentException:需要 HTTP 方法注释(例如,@GET、@POST 等) . for method StoresApi.searchStores对于方法 StoresApi.searchStores

And this is the SearchStores Method这就是 SearchStores 方法

import io.reactivex.Single
import retrofit2.Call
import retrofit2.http.GET
import retrofit2.http.Header
import retrofit2.http.Query

interface StoresApi {

    @GET("businesses/search")
    fun getStore(): Single<List<Stores>>
  fun searchStores(
      @Header("Authorization")authHeader:String,
      @Query("term")searchTerm:String,
      @Query("location")location:String): Call<List<Stores>>



}

Thank you谢谢

That's simply because you haven't annotated your searchStores function.这仅仅是因为您没有注释您的searchStores函数。 There is this fun getStore(): Single<List<Stores>> function in between the GET annotation and searchStore function and looking at the endpoint, probably the GET annotation is for the searchStore function.在 GET 注释和searchStore函数之间有一个fun getStore(): Single<List<Stores>>函数并查看端点,可能 GET 注释用于searchStore函数。 You need to annotate each function separately.您需要分别注释每个函数。

I guess it should look like this:我想它应该是这样的:

interface StoresApi {

    @GET("your-endpoint")
    fun getStore(): Single<List<Stores>>

    @GET("businesses/search")
    fun searchStores(
      @Header("Authorization") authHeader: String,
      @Query("term") searchTerm: String,
      @Query("location") location: String
    ): Call<List<Stores>>

}

Try this, You have missed the annotation for the second function,.试试这个,你错过了第二个功能的注释,。 Every function needs its own annotation.每个函数都需要自己的注解。

@GET("businesses/search")    
fun searchStores(
  @Header("Authorization") authHeader: String,
  @Query("term") searchTerm: String,
  @Query("location") location: String
): Call<List<Stores>>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android Retrofit 错误 HTTP 方法注释是必需的(例如,@GET、@POST 等) - Android Retrofit error HTTP method annotation is required (e.g., @GET, @POST, etc.) Retrofi2 Android HTTP 方法注释是必需的(例如,@GET,@POST等) - Retrofi2 Android HTTP method annotation is required (e.g., @GET, @POST, etc.) java.lang.IllegalArgumentException: HTTP 方法注释是必需的(例如,@GET、@POST 等)。尝试调用apiInterface GET 请求时出错 - java.lang.IllegalArgumentException: HTTP method annotation is required (e.g., @GET, @POST, etc.).Error when trying call apiInterface GET request 在Android上的Scala代码中改进HTTP报告“需要HTTP方法注释” - Retrofit HTTP reporting “HTTP method annotation is required” in Scala code on Android Android Retrofit2 POST调用未触发HTTP请求 - Android Retrofit2 POST call not triggering HTTP request 通过 http retrofit2 请求发送 WAV 文件 - Android Studio - Send WAV files though http retrofit2 requests - Android Studio Android Retrofit2 generics方法 - Android Retrofit2 generics method Android Retrofit2错误@Url - Android Retrofit2 error @Url Android Retrofit2 无法使 POST 请求正常工作 - Android Retrofit2 unable to get POST request working 使用 Android Studio 进行 Retrofit2:无法获得一系列加油站 - Retrofit2 with Android Studio: Cant get the array of petrol-stations
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM