[英]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.