johnzilla
johnzilla

Reputation: 13

FATAL EXCEPTION: OkHttp Dispatcher when trying to retrieve data from API using Retrofit

I have gone through a couple of Stack Overflow solutions that mostly suggested enabling Java 8, but it is still not working for me. Minimum SDK version for my app is 26. The complete error code:

E/AndroidRuntime: FATAL EXCEPTION: OkHttp Dispatcher
    Process: com.example.myRestApp, PID: 28626
    java.lang.BootstrapMethodError: Exception from call site #2 bootstrap method
        at retrofit2.DefaultCallAdapterFactory$ExecutorCallbackCall$1.onFailure(DefaultCallAdapterFactory.java:87)
        at retrofit2.OkHttpCall$1.callFailure(OkHttpCall.java:142)
        at retrofit2.OkHttpCall$1.onFailure(OkHttpCall.java:137)
        at okhttp3.RealCall$AsyncCall.run(RealCall.kt:153)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:764)
     Caused by: java.lang.ClassCastException: Bootstrap method returned null
        at retrofit2.DefaultCallAdapterFactory$ExecutorCallbackCall$1.onFailure(DefaultCallAdapterFactory.java:87) 
        at retrofit2.OkHttpCall$1.callFailure(OkHttpCall.java:142) 
        at retrofit2.OkHttpCall$1.onFailure(OkHttpCall.java:137) 
        at okhttp3.RealCall$AsyncCall.run(RealCall.kt:153) 
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
        at java.lang.Thread.run(Thread.java:764) 

I have already enabled Java 8 in my build.gradle file. My Java class is as below:

private void getPhotos() {
        ApiInterfrace apiInterfrace = ServiceGenerator.createService(ApiInterfrace.class);
        Call<List<Photo>> photosList = apiInterfrace.getPhotos();
        photosList.enqueue(new Callback<List<Photo>>() {
            @Override
            public void onResponse(Call<List<Photo>> call, Response<List<Photo>> response) {
                if (response.isSuccessful()) {
                    for (Photo photo : response.body()) {
                        photos.add(photo);
                     //   Log.d("TAG", photo.getUrl().getFull());

                    }
                    photosAdatper.notifyDataSetChanged();
                } else {
                    Log.d(TAG, "Fail");
                }
                showProgressbar(false);
            }

            @Override
            public void onFailure(Call<List<Photo>> call, Throwable t) {
                Log.d(TAG, "fail" + t.getMessage());
            }
        });
    }

Upvotes: 1

Views: 3725

Answers (1)

Adir Dayan
Adir Dayan

Reputation: 1617

Try change your gradle to version 1.8 instead of 8

compileOptions {
    sourceCompatibility = 1.8
    targetCompatibility = 1.8
}

Upvotes: 3

Related Questions