1

I have a fragment In which I have implemented some code :

    public void onViewCreated(@androidx.annotation.NonNull View v, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(v, savedInstanceState);
        button = v.findViewById(R.id.button2);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Observable<String> bookObservable = getBookObservalbel();
                Observer<String> bookObserver = getBookObserver();
                bookObservable.observeOn(Schedulers.io())
                        .subscribeOn(AndroidSchedulers.mainThread())
                        .subscribe(bookObserver);
            }
        });
    } 

 private Observer<String> getBookObserver() {
        return new Observer<String>() {
            @Override
            public void onSubscribe(@NonNull Disposable d) {

            }

            @Override
            public void onNext(@NonNull String s) {
                Log.d(TAG, "onNext: " + s);
            }

            @Override
            public void onError(@NonNull Throwable e) {

            }

            @Override
            public void onComplete() {

            }
        };
    }


    private Observable<String> getBookObservalbel() {
        return Observable.just("1", "2", "3");

    }

But while running it I am getting this error:-

    java.lang.BootstrapMethodError: Exception from call site #1 bootstrap method
        at io.reactivex.rxjava3.android.schedulers.AndroidSchedulers.<clinit>(AndroidSchedulers.java:33)
        at io.reactivex.rxjava3.android.schedulers.AndroidSchedulers.mainThread(AndroidSchedulers.java:44)
        at com.example.rxjavatut.second$1.onClick(second.java:58)
        at android.view.View.performClick(View.java:6608)
        at android.view.View.performClickInternal(View.java:6585)
        at android.view.View.access$3100(View.java:785)
        at android.view.View$PerformClick.run(View.java:25921)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:201)
        at android.app.ActivityThread.main(ActivityThread.java:6810)
        at java.lang.reflect.Method.invoke(Native Method)
     Caused by: java.lang.ClassCastException: Bootstrap method returned null

I am using these dependencies in my grade for rxjava and rxandroid

  implementation 'io.reactivex.rxjava3:rxandroid:3.0.0'

  implementation 'io.reactivex.rxjava3:rxjava:3.0.3'

I tried to run this code in the older version of rxjava and rxandroid in my mainActivity there it runs perfectly.

I am unable to figure out where the issue is, could you please share some info on what I might be doing wrong.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
Pranav Choudhary
  • 2,726
  • 3
  • 18
  • 38

1 Answers1

3

RxJava3 requires Java 8. Update your Java version:

android {
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}
Nicolas
  • 6,611
  • 3
  • 29
  • 73