错误
运行android项目 控制台报错
android.util.AndroidRuntimeException: Animators may only be run on Looper threads
详细错误
2022-09-20 09:58:53.144 5868-6007/com.example.electronicmall E/AndroidRuntime: FATAL EXCEPTION: OkHttp Dispatcher
Process: com.example.electronicmall, PID: 5868
android.util.AndroidRuntimeException: Animators may only be run on Looper threads
at android.animation.AnimatorSet.start(AnimatorSet.java:705)
at android.animation.AnimatorSet.start(AnimatorSet.java:684)
at android.animation.StateListAnimator.start(StateListAnimator.java:188)
at android.animation.StateListAnimator.setState(StateListAnimator.java:181)
at android.view.View.drawableStateChanged(View.java:22948)
at android.widget.TextView.drawableStateChanged(TextView.java:5927)
at android.view.View.refreshDrawableState(View.java:23003)
at android.view.View.dispatchAttachedToWindow(View.java:20139)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3626)
at android.view.ViewGroup.addViewInner(ViewGroup.java:5404)
at android.view.ViewGroup.addView(ViewGroup.java:5190)
at android.view.ViewGroup.addView(ViewGroup.java:5130)
at android.view.ViewGroup.addView(ViewGroup.java:5103)
at com.example.electronicmall.test.User.UserMineActivity$1$1.onResponse(UserMineActivity.java:141)
at com.squareup.okhttp.Call$AsyncCall.execute(Call.java:168)
at com.squareup.okhttp.internal.NamedRunnable.run(NamedRunnable.java:33)
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:929)
解决方案
原因
对于所创建的线程, 若代码涉及页面UI更改。根据android官网规定, 为确保程序安全, 需放置 runOnUiThread类型的线程中。
原创不易
转载请标明出处
如果对你有所帮助 别忘啦点赞支持哈