How to avoid FATAL EXCEPTION in OkHttp Dispatcher after callback Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of How to avoid FATAL EXCEPTION in OkHttp Dispatcher after callback without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I’m getting this exception when performing ui actions after receiving callback from OkHttp.

FATAL EXCEPTION: OkHttp Dispatcher Process: org.example.verificationserviceexample, PID: 20421 android.util.AndroidRuntimeException: Animators may only be run on Looper threads at android.animation.ValueAnimator.cancel( at android.animation.AnimatorSet.cancel( at at at at at at at at android.view.View.drawableStateChanged( at android.widget.TextView.drawableStateChanged( at at android.view.View.refreshDrawableState( at android.view.View.setEnabled( at android.widget.TextView.setEnabled( at org.example.verificationserviceexample.MainActivity.renderButtons( at org.example.verificationserviceexample.MainActivity.onAudioStateChanged( at at at com.bssys.spitchmobilesdk.VerificationService.stopAudio( at com.bssys.spitchmobilesdk.VerificationService.stopEnrollment( at org.example.verificationserviceexample.MainActivity.lambda$null$0$MainActivity( at org.example.verificationserviceexample.MainActivity$$Lambda$3.onSpitchResult(Unknown Source) at com.bssys.spitchmobilesdk.VerificationService$1.onFailure( at okhttp3.RealCall$AsyncCall.execute( at at java.util.concurrent.ThreadPoolExecutor.runWorker( at java.util.concurrent.ThreadPoolExecutor$ at

And this is the code that I’m using:

public void addVoicePrintFromSource(Pipe source, SpitchConfig config, @NonNull String speakerId, Callback callback){

        RequestBody requestBody = new RequestBody() {
            public MediaType contentType() {
                return MediaType.parse("audio/x-pcm; rate="+config.getRate());

            public void writeTo(BufferedSink sink) throws IOException {
        Request request = new Request.Builder()



I’m using an OkIo Pipe to populate RequestBody with audio data

Thanks in advance!


Don’t change the state of views from other threads, which includes OKHTTP callbacks. If you need to, do it on a runOnUiThread block. By calling setEnabled, you’re causing various UI functions to be called that can’t run on that thread.

We are here to answer your question about How to avoid FATAL EXCEPTION in OkHttp Dispatcher after callback - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji