0

I am loading some data from the server using the Retrofit Library. While loading some data from the server It is creating trouble. Some time the data is loaded. Some time is not loading and showing the following Exception in the Log. I am not understanding what to do now.

Exception:

java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 2418 path $.data[2].run

I am getting error in this java class on Line " return Observable.fromCallable(new Callable()" and on line "return call.execute();".

public class APIExecutor

{

public static Observable<Response> call(final Call call)
{

    BackgroundThread bgThread = new BackgroundThread();
    bgThread.start();

    Handler bgHandler = new Handler(bgThread.getLooper());
    Observable<Response> observable = Observable.defer(new Func0<Observable<Response>>()
    {
        @Override
        public Observable<Response> call()
        {
            return Observable.fromCallable(new Callable<Response>() {
                @Override
                public Response call() throws Exception 
                {


                    return call.execute();
                }
            });
        }
    });

    return observable
            .subscribeOn(HandlerScheduler.from(bgHandler))
            .observeOn(AndroidSchedulers.mainThread());
}

}

ZIA ANSARI
  • 131
  • 1
  • 11

1 Answers1

3

You're expecting a Json Object from your server but you're receiving a non-Json response.

You can test your API with either Postman or put a HTTP Logger on your requests to see what you're actually getting.

I can't understand why you're using a custom Observable here. If you're using Retrofit2 along with RxJava2, you ought use it the proper way by using the RxJava2CallAdapterFactory to receive Observables directly from Retrofit itself.

Anyhow as I already said the problem is with your response from the server. You must somehow see what you're actually getting from the server.

2hamed
  • 7,739
  • 11
  • 60
  • 102