Skip to content Skip to sidebar Skip to footer

Error When Using Retrofit

I'm trying to get data from web server.I'n new with Retrofit ,and I have error 'No Retrofit annotation found (parameter#1)' when try launch my app,I dont understand what cause this

Solution 1:

You must use videoApi.getFeaturedVideo(new Callback<List<Video>>() method like that :

Call<List<Video>> call=videoApi.getFeaturedVideo();
call.enqueue(new Callback<List<Video>>() {
            @Overridepublic void onResponse(Call<List<Video>> call, Response<List<Video>> response) {


            }

            @Overridepublic void onFailure(Call<List<Video>> call, Throwable t) {

            }
        });

And your api :

publicinterfaceVideoApi{

    @GET("/videos/featured")
    Call<List<Video>>getFeaturedVideo();
}

Still if you have errors try this too :

import javax.annotation.Generated;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

@Generated("org.jsonschema2pojo")
publicclassVideo {

@SerializedName("url")
@ExposeprivateString url;
@SerializedName("title")
@ExposeprivateString title;
@SerializedName("description")
@ExposeprivateString description;
@SerializedName("score")
@ExposeprivateInteger score;

/**
* 
* @return
* The url
*/publicStringgetUrl() {
return url;
}

/**
* 
* @paramurl
* The url
*/publicvoidsetUrl(String url) {
this.url = url;
}

/**
* 
* @return
* The title
*/publicStringgetTitle() {
return title;
}

/**
* 
* @paramtitle
* The title
*/publicvoidsetTitle(String title) {
this.title = title;
}

/**
* 
* @return
* The description
*/publicStringgetDescription() {
return description;
}

/**
* 
* @paramdescription
* The description
*/publicvoidsetDescription(String description) {
this.description = description;
}

/**
* 
* @return
* The score
*/publicIntegergetScore() {
return score;
}

/**
* 
* @paramscore
* The score
*/publicvoidsetScore(Integer score) {
this.score = score;
}

}

Make sure u have added this to your gradle

compile'com.google.code.gson:gson:2.4'

And try this site to create your POJO class :Json Schema to POJO

Post a Comment for "Error When Using Retrofit"