101

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.** { *; }
reVerse
  • 35,075
  • 22
  • 89
  • 84
mk72
  • 1,307
  • 2
  • 8
  • 15
  • You should verify your request code, all retrofit request annotations should be there and well formatted. Check more here: https://readyandroid.wordpress.com/no-retrofit-annotation-found-retrofit/ – Ready Android Jun 08 '18 at 08:47

18 Answers18

343

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

David Vávra
  • 18,446
  • 7
  • 48
  • 56
57

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.

NullPointerException
  • 3,978
  • 4
  • 34
  • 52
  • 8
    make sure it belongs to the *right* retrofit package too. In my case I had accidentally imported an annotation from retrofit instead of retrofit2 – Jan K Jan 13 '17 at 18:32
22

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);
Irshu
  • 8,248
  • 8
  • 53
  • 65
10

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.

KingJinho
  • 683
  • 1
  • 6
  • 23
9

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

MrVasilev
  • 1,503
  • 2
  • 17
  • 34
7

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

Alberto M
  • 1,608
  • 1
  • 18
  • 42
7

You need to include @Body if you are doing post

Richard Kamere
  • 749
  • 12
  • 10
4

(Kotlin) I solved here:

//@FormUrlEncoded // Don't used
@POST("orders")
fun saveOrders(@Body orders: Orders): Call<OrdersResponse>
Infomaster
  • 793
  • 7
  • 8
  • You were getting the error because you forgot to add @ Field annontation to your parameter and used @ FormUrlEncoded – P1NG2WIN Dec 24 '20 at 00:10
3

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/

dominik4142
  • 556
  • 3
  • 14
3

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

ngoson
  • 583
  • 5
  • 14
2

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.

Francesco Florio
  • 1,184
  • 14
  • 16
2

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

lucasddaniel
  • 1,779
  • 22
  • 22
2

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'
erhan
  • 31
  • 4
1

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.

Sfseyhan
  • 1,321
  • 1
  • 13
  • 18
1

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?>
Nouman Ch
  • 4,023
  • 4
  • 29
  • 42
1

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.

GilbertS
  • 591
  • 8
  • 12
1

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
AskQ
  • 4,215
  • 7
  • 34
  • 61
0

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

Shojaeddin
  • 1,851
  • 1
  • 18
  • 16