gpt4 book ai didi

flutter - Dart NoSuchMethodError输出指的是什么闭包?

转载 作者:行者123 更新时间:2023-12-03 03:59:00 24 4
gpt4 key购买 nike

我有一个不稳定的应用程序(v1.2.1),我正在尝试调试一个在 Debug模式下无法重现的错误。我知道根本原因是在空对象上调用forEach,但是我正在尝试查找代码中所指的forEach。我不理解错误消息的“尝试调用”部分,并且在Dart NoSuchMethodError类文档中找不到关于它的任何详细信息。这是错误:

NoSuchMethodError: The method 'forEach' was called on null.
Receiver: null
Tried calling: forEach(Closure: (CustomObject) => Null)

该错误是否表示它发生在格式为forEach((CustomObject)=> {method body})的forEach上,还是在格式为(CustomObject)=> {method body}的闭包内部的forEach上?

例如。会是这样吗?
methodOne(List<CustomObject> fakeObjects) {
fakeObjects.forEach((CustomObject thingOne) {
print(thingOne);
});
}

或类似这样的东西:
methodTwo(CustomObject thingOne) {
...some code
listOfItems.forEach((String item) {
print(item);
});
}

最佳答案

我已经重现了这个错误。
您的fakeObjects为null,请参见以下代码段和图片

List<String> fakeObjects = null;
fakeObjects.forEach((String thingOne) {
print(thingOne);
});

enter image description here

输出量
The method 'forEach' was called on null.
Receiver: null
Tried calling: forEach(Closure: (String) => Null)

关于flutter - Dart NoSuchMethodError输出指的是什么闭包?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58757074/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com