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>>() {
            @Override
            public void onResponse(Call<List<Video>> call, Response<List<Video>> response) {


            }

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

            }
        });

And your api :

public interface VideoApi {

    @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")
public class Video {

@SerializedName("url")
@Expose
private String url;
@SerializedName("title")
@Expose
private String title;
@SerializedName("description")
@Expose
private String description;
@SerializedName("score")
@Expose
private Integer score;

/**
* 
* @return
* The url
*/
public String getUrl() {
return url;
}

/**
* 
* @param url
* The url
*/
public void setUrl(String url) {
this.url = url;
}

/**
* 
* @return
* The title
*/
public String getTitle() {
return title;
}

/**
* 
* @param title
* The title
*/
public void setTitle(String title) {
this.title = title;
}

/**
* 
* @return
* The description
*/
public String getDescription() {
return description;
}

/**
* 
* @param description
* The description
*/
public void setDescription(String description) {
this.description = description;
}

/**
* 
* @return
* The score
*/
public Integer getScore() {
return score;
}

/**
* 
* @param score
* The score
*/
public void setScore(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"