Click here to Skip to main content
15,891,745 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys,

im trying to get data from AN API Called spoonaculari. And the android studio is giving me an error (given under the code)






    try {
        HttpResponse<JsonNode> response = Unirest.get("https://spoonacular-recipe-food-nutrition-v1.p.mashape.com/recipes/random?number=5&tags=lunch")
                .header("X-Mashape-Key", "<MASHAPEkey>")
                .header("X-Mashape-Host", "spoonacular-recipe-food-nutrition-v1.p.mashape.com")
                .asJson();

        JSONObject myObj = response.getBody().getObject();

        String title = myObj.getString("title");

        JSONArray resultsTitle = myObj.getJSONArray(title);

        String[] recipeTitle = new String[resultsTitle.length()];
        String[] time = new String[resultsTitle.length()];
        String[] rating = new String[resultsTitle.length()];
        String[] img = new String[resultsTitle.length()];

        for (int i = 0; i<resultsTitle.length(); i++){
            JSONObject jsonObject = resultsTitle.getJSONObject(i);

            recipeTitle[i] = jsonObject.getString("title");
            time[i] = jsonObject.getString("readyInMinutes");
            rating[i] = jsonObject.getString("aggregateLikes");
            img[i]= jsonObject.getString("image");
        }


        for (int i = 0; i<resultsTitle.length(); i++){

            ItemRecipe item = new ItemRecipe();
            item.setRecipe(recipeTitle[i]);
            item.setTime(time[i]);
            item.setRating(rating[i]);
            item.setImg(img[i]);
            itemList.add(item);
        }

    } catch (UnirestException e) {
        e.printStackTrace();
    } catch (JSONException e) {
        e.printStackTrace();
    }

    return itemList;

}



FATAL EXCEPTION: main
                                                                                  Process: com.sigmondgatt.myshoppinghelper, PID: 19894
                                                                                  java.lang.NoSuchFieldError: No field INSTANCE of type Lorg/apache/http/conn/ssl/AllowAllHostnameVerifier; in class Lorg/apache/http/conn/ssl/AllowAllHostnameVerifier; or its superclasses (declaration of 'org.apache.http.conn.ssl.AllowAllHostnameVerifier' appears in /system/framework/framework.jar:classes3.dex)


What I have tried:

I found that i need to enable AllowAllHostnameVerifier
Can someone help me please ??
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900