无法进行spoonacular get调用

eulz3vhy  于 2021-07-11  发布在  Java
关注(0)|答案(0)|浏览(244)

我正在尝试使用androidstudio中的spoonacular搜索配方。
我正试图通过以下代码拨打电话:

public interface RecipeApi {
    // SEARCH
    @GET("findByIngredients")
    Call<RecipeApus> searchRecipe(@Query("apiKey") String apiKey, @Query("ingredients") String ingredients);
}

这就是我的生活 RecipeApus :

public class RecipeApus {

    @SerializedName("id")
    @Expose
    private Integer id;
    @SerializedName("title")
    @Expose
    private String title;
    @SerializedName("image")
    @Expose
    private String image;
    @SerializedName("imageType")
    @Expose
    private String imageType;
    @SerializedName("usedIngredientCount")
    @Expose
    private Integer usedIngredientCount;
    @SerializedName("missedIngredientCount")
    @Expose
    private Integer missedIngredientCount;
    @SerializedName("missedIngredients")
    @Expose
    private List<MissedIngredient> missedIngredients = null;
    @SerializedName("usedIngredients")
    @Expose
    private List<UsedIngredient> usedIngredients = null;
    @SerializedName("unusedIngredients")
    @Expose
    private List<UnusedIngredient> unusedIngredients = null;
    @SerializedName("likes")
    @Expose
    private Integer likes;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getImage() {
        return image;
    }

    public void setImage(String image) {
        this.image = image;
    }

    public String getImageType() {
        return imageType;
    }

    public void setImageType(String imageType) {
        this.imageType = imageType;
    }

    public Integer getUsedIngredientCount() {
        return usedIngredientCount;
    }

    public void setUsedIngredientCount(Integer usedIngredientCount) {
        this.usedIngredientCount = usedIngredientCount;
    }

    public Integer getMissedIngredientCount() {
        return missedIngredientCount;
    }

    public void setMissedIngredientCount(Integer missedIngredientCount) {
        this.missedIngredientCount = missedIngredientCount;
    }

    public List<MissedIngredient> getMissedIngredients() {
        return missedIngredients;
    }

    public void setMissedIngredients(List<MissedIngredient> missedIngredients) {
        this.missedIngredients = missedIngredients;
    }

    public List<UsedIngredient> getUsedIngredients() {
        return usedIngredients;
    }

    public void setUsedIngredients(List<UsedIngredient> usedIngredients) {
        this.usedIngredients = usedIngredients;
    }

    public List<UnusedIngredient> getUnusedIngredients() {
        return unusedIngredients;
    }

    public void setUnusedIngredients(List<UnusedIngredient> unusedIngredients) {
        this.unusedIngredients = unusedIngredients;
    }

    public Integer getLikes() {
        return likes;
    }

    public void setLikes(Integer likes) {
        this.likes = likes;
    }

}

当我试着用手机打电话的时候 MainActivity ,这是我得到的:

java.lang.IllegalArgumentException: Unable to create converter for class com.example.app.DTO.RecipeApus
    for method RecipeApi.searchRecipe
    at retrofit2.Utils.methodError(Utils.java:54)
    at retrofit2.HttpServiceMethod.createResponseConverter(HttpServiceMethod.java:126)
    at retrofit2.HttpServiceMethod.parseAnnotations(HttpServiceMethod.java:85)
    at retrofit2.ServiceMethod.parseAnnotations(ServiceMethod.java:39)
    at retrofit2.Retrofit.loadServiceMethod(Retrofit.java:202)
    at retrofit2.Retrofit$1.invoke(Retrofit.java:160)
    at java.lang.reflect.Proxy.invoke(Proxy.java:1006)
    at $Proxy0.searchRecipe(Unknown Source)
    at com.example.foodsaver.MainActivity.lambda$onActivityResult$0$MainActivity(MainActivity.java:122)
    at com.example.foodsaver.-$$Lambda$MainActivity$CpUgDzAm4SZLo6GEShMRZXPDjDQ.onSuccess(Unknown Source:4)
    at com.google.android.gms.tasks.zzn.run(Unknown Source:4)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:214)
    at android.app.ActivityThread.main(ActivityThread.java:7050)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964)
 Caused by: java.lang.IllegalArgumentException: Could not locate ResponseBody converter for class com.example.foodsaver.DTO.RecipeApus.
  Tried:
   * retrofit2.BuiltInConverters
   * retrofit2.OptionalConverterFactory
    at retrofit2.Retrofit.nextResponseBodyConverter(Retrofit.java:384)
    at retrofit2.Retrofit.responseBodyConverter(Retrofit.java:345)
    at retrofit2.HttpServiceMethod.createResponseConverter(HttpServiceMethod.java:124)
        ... 16 more

我该怎么解决这个问题?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题