Unhandled Exception: NoSuchMethodError: The getter 'length' was called on null. Don't know the reason

Unhandled Exception: NoSuchMethodError: The getter 'length' was called on null. Don't know the reason

我知道这个错误已经有人多次回答了,但我认为我的情况有点不同。到目前为止,我的 flutter 运行ning 很好,没有任何困难。但是突然间它开始给我这个错误 app.It 运行 is not opening on app on installing.This 错误只是在安装应用程序的过程中不断出现,我不知道它来自哪里。

请指导我如何找到问题所在以及如何解决问题。

这个错误可能是准确的,因为你给了一个空值 jsonDecode:

var jsonString = null;
var parsed = jsonDecode(jsonString);
print(parsed.length);
// NoSuchMethodError: The getter 'length' was called on null.

在您的项目中搜索 jsonDecodejson.decode 并且当 jsonString 为 null 时 ether 不调用它并显示错误消息,或将其替换为默认的 jsonString:

var jsonString = null;
const defaultJson = '{}';
var parsed = jsonDecode(jsonString ?? defaultJson);
print(parsed.length);
// 0