gpt4 book ai didi

java - 安卓5.1 : Attempt to write to field 'java.util.ArrayList android.animation.AnimatorSet$Node.nodeDependents' on a null object reference

转载 作者:行者123 更新时间:2023-12-01 11:31:40 25 4
gpt4 key购买 nike

java.lang.NullPointerException:尝试写入空对象引用上的字段“java.util.ArrayList android.animation.AnimatorSet$Node.nodeDependents”

从 Android 5.0 迁移到 5.1 后,我遇到了这个问题,当我尝试使用克隆的 LayoutInflater 进行膨胀时会发生此问题。如果我只使用常规布局充气机就可以了。此外,这种膨胀也发生在带有 threadPool 执行器的后台线程上,因为出于性能原因需要同时膨胀两个相同的布局。如果我改用序列化执行器也可以。

final LayoutInflater bgLayoutInflater = layoutInflater.cloneInContext(getContext());
final ViewGroup rootView = (ViewGroup) bgLayoutInflater.inflate(resourceId, null, false);

link to the AOSP where crash happens, line 699

有什么想法吗?

最佳答案

最后我自己解决了这个问题。不管新的 5.1 AOSP 更改应该返回一个更好的错误来告诉我出了什么问题,我在后台线程中膨胀了一个大布局,风险由我自己承担。

这就是我相信发生的事情。

final LayoutInflater layoutInflater = (LayoutInflater)
getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

我需要以最快的时间膨胀两个大布局(每个 600 毫秒),因此我决定使用 asyncTask 和 threadPoolExecutor 来执行两个膨胀任务。但我无法实现它,因为 SystemService 中的layoutInflater 是同步的。所以我做了一个克隆的充气机,解决了这个问题,直到5.1。

现在我可以修复它了

 final LayoutInflater layoutInflater = LayoutInflater.from(getContext()); 

这样每个充气机都可以并行地完成自己的工作。同样,我仍然面临着不在 UI 线程上膨胀的风险,将来的新更新可能仍会在某个地方破坏它。

关于java - 安卓5.1 : Attempt to write to field 'java.util.ArrayList android.animation.AnimatorSet$Node.nodeDependents' on a null object reference,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30333200/

25 4 0