簡體   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.)

它一直在 Android Studio 中向我顯示這個錯誤,我正在使用改造 2,試圖從 Yelp API 獲取數據,它一直向我顯示這個消息

java.lang.RuntimeException:無法啟動活動 ComponentInfo{sf.alomari.yelp/sf.alomari.view.MainActivity}:java.lang.IllegalArgumentException:需要 HTTP 方法注釋(例如,@GET、@POST 等) . 對於方法 StoresApi.searchStores

這就是 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>>



}

謝謝

這僅僅是因為您沒有注釋您的searchStores函數。 在 GET 注釋和searchStore函數之間有一個fun getStore(): Single<List<Stores>>函數並查看端點,可能 GET 注釋用於searchStore函數。 您需要分別注釋每個函數。

我想它應該是這樣的:

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>>

}

試試這個,你錯過了第二個功能的注釋,。 每個函數都需要自己的注解。

@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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM