经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 移动开发 » Android » 查看文章
java.lang.IllegalStateException: Bindings already cleared. 2021-01-28
来源:cnblogs  作者:Seachal  时间:2021/2/1 11:32:41  对本文有异议

java.lang.IllegalStateException: Bindings already cleared.

使用 ButterKnife 从 7.x.x 升级到 10.x.x 后,某个 viewPager 中的
的 Fragment 方法报以下错误:

  1. java.lang.IllegalStateException: Bindings already cleared.

查看代码git历史,是从

  1. ButterKnife.unbind(this);

变为了

  1. unbinder.unbind();

然后发现,

父类:

  1. @Override
  2. public void onDestroyView() {
  3. super.onDestroyView();
  4. unbinder.unbind();
  5. }

子类

  1. @Override
  2. public void onDestroyView() {
  3. super.onDestroyView();
  4. unbinder.unbind();
  5. }

中都调用了 unbinder.unbind();
猜测是因为父类已经执行过unbind()了,子类再去执行unbind()引发的异常。

所以跳进 unbind() 查看源码:

  1. public interface Unbinder {
  2. @UiThread void unbind();
  3. Unbinder EMPTY = () -> { };
  4. }

选中unbind,然后用快捷键 option+command+B,跳到实现中:

  1. @Override
  2. @CallSuper
  3. public void unbind() {
  4. AbsWebViewActivity target = this.target;
  5. if (target == null) throw new IllegalStateException("Bindings already cleared.");
  6. this.target = null;
  7. target.mWebView = null;
  8. target.tvLoadFail = null;
  9. target.btnLoadAgain = null;
  10. target.llLoadError = null;
  11. target.llProgressbar = null;
  12. }

果然发现了new IllegalStateException("Bindings already cleared.");

所以子类删除 unbinder.unbind()就可以了,子类修改如下:

  1. @Override
  2. public void onDestroyView() {
  3. super.onDestroyView();
  4. // unbinder.unbind();
  5. }

原文链接:http://www.cnblogs.com/Seachal/p/javalangillegalstateexception-bindings-already-cle.html

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号