当前位置: 首页 > 知识库问答 >
问题:

未处理的异常:NoSuch方法错误:方法'[]'在flutter上被调用为空

万俟经纶
2023-03-14

当我将其更改为list时,出现以下错误:

E/flutter ( 6925): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: NoSuchMethodError: The method '[]' was called on null.
E/flutter ( 6925): Receiver: null
E/flutter ( 6925): Tried calling: []("interest")

这里是我的小部件构建:

@override
    Widget build(BuildContext context) {
      timeDilation = 2.0;
      return WillPopScope(
        onWillPop: () async => false,
        child: Scaffold(
          resizeToAvoidBottomInset: false,
          backgroundColor: kYellow,
          appBar: AppBar(
            leading: Hero(
              tag: 'animasilogo',
              child: Container(
                margin: EdgeInsets.all(5.0),
                child: Image.asset('assets/img/lemonlime.png'),
              ),
            ),
            title: Text('Simulator'),
            actions: [
              IconButton(
                icon: const Icon(Icons.exit_to_app),
                onPressed: () {
                  SharedPref.signOut();
                  Navigator.pushNamed(context, LoginScreen.id);
                },
              )
            ],
          ),
          body: RefreshIndicator(
            onRefresh: () => _fetchData(),
            child: loading
                ? Center(child: CircularProgressIndicator())
                : ListView.builder(
              itemCount: _loanmodel.length,
              itemBuilder: (context, i) {
              final data =_loanmodel[i];
              return Container(
                alignment: Alignment.topLeft,
                margin: const EdgeInsets.only(top: 15.0),
                  padding: EdgeInsets.all(20.0),
                child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                 Text("Interest :  " + data.interest , style: DefaultTextStyle.of(context).style.apply(fontSizeFactor: 1.5), textAlign: TextAlign.justify),
                  Text("Balance :  " + data.balance,  style: DefaultTextStyle.of(context).style.apply(fontSizeFactor: 1.5),textAlign: TextAlign.justify),
                  Text("Principal : " + data.principal,  style: DefaultTextStyle.of(context).style.apply(fontSizeFactor: 1.5),textAlign: TextAlign.justify),
                  Text("Installment :" + data.installment,  style: DefaultTextStyle.of(context).style.apply(fontSizeFactor: 1.5),textAlign: TextAlign.justify),
                  Divider(
                    color: Colors.black,
                  ),

                ],
              ),
                );
              },
            ),
          ),
        ),
      );
    }
  }

对于API、模型和其他函数,您可以在未处理的异常中检查我的另一篇文章:键入“\u InternalLinkedHashMap”

共有1个答案

段干博明
2023-03-14

确保您收到的部分数据不为空。应该接收“兴趣”的部分为空,因为它是您试图处理的数据的第一部分,所以其他部分也可能为空

 类似资料:
  • 你好,我是一个入门的flutter开发人员,我想用我的CloudFireStore数据库中的数据做一个列表。我不知道该怎么做。如果您对我的代码有任何帮助或建议,我们将不胜感激 这是正在出错的代码示例 这里有一条错误消息。如果有人能帮我解决这个问题我会从幸福中发疯

  • 我正在尝试用flatter和laravelapi构建一个应用程序。在我开始实现功能之前,一切都很顺利。我收到此错误

  • 我正在为Spring MVC中的异常处理开发示例演示应用程序。我正在尝试使用@ControllerAdvice处理异常 我遵循了本链接中描述的步骤。 但是当我运行我的应用程序时,我得到了以下错误 以下是我正在学习的课程 应用程序异常。JAVA 控制器类 ApplicationExceptionController。JAVA 下面是GlobalExceptionHandler类 GlobalExce

  • 因此,我尝试在firestore中使用一个文档创建集合,从我以fiels形式收集的变量中,代码如下: 这是我得到的错误代码: F/crash_dump32(18407):crash_dump.cpp:474]未能附加到线程181:权限被拒绝I/e.firebase_com(17852):线程[5, tid=17868, WaitingInMain SignalCatcherLoop,线程=0xe1

  • 我正在和Java8一起做项目,发现了一个我无法理解的情况。 我有这样的代码: 这段代码运行良好,但我可以使用方法引用重写它: 而这段代码没有编译,在方法引用中给出了不兼容的抛出类型*SomeException*。 IDEA还向我提供了错误

  • 本文向大家介绍Angular处理未可知异常错误的方法详解,包括了Angular处理未可知异常错误的方法详解的使用技巧和注意事项,需要的朋友参考一下 写在前面 代码写得再好,始终都无法完整的处理所有可能产生异常,特别是生产环境中的应用,很大一部分是数据来自用户、远程,很难保证所有数据都按程序规定的产生。事实上,除非测试人员发现或者客户报告,否则都无法得知。因此,将应用产生的未可知异常进而上报是非常重