No Retrofit annotation found. (parameter #1)

AndroidAndroid StudioRetrofit

Android Problem Overview


I want get RSS code from a URL with Retrofit and if I enter url staticly in the get annotation everything is OK but with dynamic url I get an error.

My interface service :

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

And calling getRss method :

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());
        }

I get the following error:

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

Note: I added below line to proguard.cfg but it didn't work

-keep class retrofit.** { *; }

Android Solutions


Solution 1 - Android

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

Solution 2 - Android

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.

Solution 3 - Android

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

Solution 4 - Android

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

Solution 5 - Android

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.

Solution 6 - Android

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

Solution 7 - Android

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/

Solution 8 - Android

(Kotlin) I solved here:

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

Solution 9 - Android

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.

Solution 10 - Android

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

Solution 11 - Android

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

Solution 12 - Android

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.

Solution 13 - Android

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

Solution 14 - Android

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.

Solution 15 - Android

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

Solution 16 - Android

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'

Solution 17 - Android

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionmk72View Question on Stackoverflow
Solution 1 - AndroidDavid VávraView Answer on Stackoverflow
Solution 2 - AndroidNullPointerExceptionView Answer on Stackoverflow
Solution 3 - AndroidIrshuView Answer on Stackoverflow
Solution 4 - AndroidMrVasilevView Answer on Stackoverflow
Solution 5 - AndroidKingJinhoView Answer on Stackoverflow
Solution 6 - AndroidAlberto MView Answer on Stackoverflow
Solution 7 - Androiddominik4142View Answer on Stackoverflow
Solution 8 - AndroidInfomasterView Answer on Stackoverflow
Solution 9 - AndroidFrancesco FlorioView Answer on Stackoverflow
Solution 10 - AndroidlucasddanielView Answer on Stackoverflow
Solution 11 - AndroidngosonView Answer on Stackoverflow
Solution 12 - AndroidSfseyhanView Answer on Stackoverflow
Solution 13 - AndroidNouman ChView Answer on Stackoverflow
Solution 14 - AndroidGilbertSView Answer on Stackoverflow
Solution 15 - AndroidAskQView Answer on Stackoverflow
Solution 16 - AndroiderhanView Answer on Stackoverflow
Solution 17 - AndroidShojaeddinView Answer on Stackoverflow