0

I am using Retrofit for my network calls. Unfortunately, it seems that the data I am able to get is incomplete.

When I open the link in the browser, it displays large json data. http://test.holmusk.com/food/search?q=apple

But, when I use Retrofit in my Android App, it stops somewhere in the middle as an error with a 200 error status and null error body.

Here is the last part of the data logged:

 "value": 119
    },
    "polyunsaturated": {
07-09 21:07:27.129  25661-25661/divinegrace.com.myapplication E/SearchFoodService﹕ 200 null

Here are my codes:

public class SearchFoodService {

    IMyAppService mIMyAppService;

    private final String LOG_TAG = "SearchFoodService";

    public SearchFoodService(IMyAppService mIMyAppService) {
        this.mIMyAppService = mIMyAppService;
    }

    public void searchForFoodInformation(String foodName) {
        Callback<Void> callback = new Callback<Void>() {
            @Override
            public void success(Void s, Response response) {
                Log.d(LOG_TAG, response.toString());
            }

            @Override
            public void failure(RetrofitError error) {
                Log.e(LOG_TAG, "" + error.getResponse().getStatus() + " " + error.getBody());
            }
        };

        mIMyAppService.searchFood(foodName, callback);
    }
}



public interface IMyAppService {

    @GET(EndPoints.SEARCH_FOOD)
    void searchFood(@Query("q") String foodName,
                    Callback<Void> callback);


public class MyAppService {
    private IMyAppService mService;


    public MyAppService() { }

    public IMyAppService getMyAppService() {

        if (mService != null) {
            return mService;
        }

        RestAdapter restAdapter = new RestAdapter.Builder()
                .setEndpoint(Constants.TEST_URL)
                .build();

        restAdapter.setLogLevel(RestAdapter.LogLevel.FULL);

        mService = restAdapter.create(IMyAppService.class);

        return mService;
    }
}
Viny
  • 33
  • 5
  • `200` is not an error status. `200` status is successful response. – eleven Jul 09 '15 at 14:03
  • I know, but as you see in the code, I printed the error status and body in the retrofit failure code block. In the logs, it printed as "200 null" and the data is incomplete. – Viny Jul 09 '15 at 14:25
  • You pass `Void` callback. Actually this is senseless. `Retrofit` just doesn't know how to parse the answer. `Callback` has generic which should be `pojo` object of your response. – eleven Jul 09 '15 at 14:35
  • Well, I am in the early stages of development. I did put the object there earlier but changed it to void to check if it has something to do with the object I am passing in the callback. But the reply are just the same. – Viny Jul 09 '15 at 14:37
  • Hello, I'm trying to fix the object. Probably there;s something wrong there. Will be updating if it fixes the issue. thanks – Viny Jul 09 '15 at 14:46
  • Hello. it seems that there was a problem with my pojo earlier. I fixed it and changed void to the object that I wanted. It works now. Thanks – Viny Jul 09 '15 at 14:54
  • I am having same problem https://stackoverflow.com/q/58615323/7639056 – Kaushik Burkule Nov 04 '19 at 11:10

0 Answers0