找不到任何修复注释(参数 # 1)

我想从一个带有 Retrofit的 URL 中获取 RSS 代码,如果我在 get 注释中静态地输入 URL,那么一切都没问题,但是如果使用动态 URL,我会得到一个错误。

我的接口服务:

public interface AllNewsService {
@GET("/fa/rss/{url}")
void getRss( @Path("url") String nGroup ,  Callback<AllNewsRss> callback);}

调用 getRss 方法:

DataGetter dg = new DataGetter();
dg.get().getRss("allnews" ,new Callback<AllNewsRss>() {
@Override
public void success(AllNewsRss allNewsRss, Response response) {
Log.d(TAG,"success");
}


@Override
public void failure(RetrofitError error) {
Log.d("*********",error.toString());
}

我得到以下错误:

retrofit.RetrofitError: AllNewsService.getRss: No Retrofit annotation found. (parameter #1)

注意: 我给 proguard.cfg添加了下面一行,但是没有用

-keep class retrofit.** { *; }
87772 次浏览

You probably forgot to initialise adapter first, as mentioned in retrofit api:

RestAdapter restAdapter = new RestAdapter.Builder()
.setEndpoint("https://api.github.com")
.build();
GitHubService service = restAdapter.create(GitHubService.class);

http://square.github.io/retrofit/

My problem was that I had the @POST annotation, but forgot the @Body annotation for the parameter.

Addition to Destil's answer

Make sure the parameters you pass to the retrofit interface methods(i.e callbacks, headers, body ) are only belongs to retrofit package. e.g. Not custom callbacks that you want on your own.

Also make sure you add @Query or @Field for all the parameters , depending on whether you issuing GET/POST.

eg:

@GET("/api/Books/GetAll")
void GetRecentBooks(@Query int Offset, Callback<List<Book>> cb);

Please check the Path class you are using and make sure that the package is retrofit2.http.Path instead of org.simpleframework.xml.Path. It is a common Retrofit annotation mistake.

In my case, I just forgot to remove Callback parameter for the service call when I start using retrofit 2. Make sure you didn't do the silly mistake I did.

I had the @Post annotation but forgot the @Field and @FormUrlEncoded annotations

Remove from retrofit interface all parameters that not belong to this.

My problem was that I am using Kotlin coroutines and used 'suspend' in the Retrofit GET method. Just remove it and everything works fine.

It's way too late, but i just faced the same issue. I was using retrofit 2.5.0 with 'deferred' and 'await' on my retrofit interface and viewModel. And I read from retrofit github that from 2.6.0 deferred is deprecated and we can switch from deferred to 'suspend'. before i moved my retrofit version up, i just simply changed from deferred to suspend and run it, and got the same error. I solved it by moving my retrofit version from 2.5.0 to 2.6.0.

My point is that maybe there may be a chance that current retrofit version in your app doesn't support the way you use retrofit in your retrofit related classes or interfaces.

I forgot to add @Field("")

Previously

   @POST("/api/verify-phone")
@FormUrlEncoded
fun sendOTP(phone_number: String): Observable<SignInResponse?>

Fixed

@POST("/api/verify-phone")
@FormUrlEncoded
fun sendOTP(@Field("phone")phone_number: String): Observable<SignInResponse?>

This happened to me when I was using suspend functions in the network service interface like so.

interface Service {
@GET("chapters")
suspend fun fetchChapters() : List<NetworkChapter>

I solved it by doing 2 things. 1. Using Gson instead of Moshi library. Remove moshi converter from retrofit and use Gson converter. 2. Removing coroutine converter factory from retrofit. I think this one was the main problem.

(Kotlin) I solved here:

//@FormUrlEncoded // Don't used
@POST("orders")
fun saveOrders(@Body orders: Orders): Call<OrdersResponse>

In my case I used Retrofit 2.5.0 instead of the newest version. Update to 2.9.0 and thing went fine again.

Actual problem for me was old okhttp. Getting same error even updating retrofit to 2.6.0.

okhttp_version = "3.12.1"//remove
okhttp_version = "4.4.0"//works

In my case I use @Post and @body but use multiple options instead a class when I use give object instead of parameters it solves my problems

make sure you add all dependencies required:

implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation 'com.squareup.okhttp3:logging-interceptor:4.5.0'

You need to include @Body if you are doing post