【问题标题】:Try {} catch(error) {} error when printing (error) in Dart/Flutter在 Dart/Flutter 中打印(错误)时尝试 {} catch(error) {} 错误
【发布时间】:2019-12-22 13:20:09
【问题描述】:

我捕获的print(error) 组件: catch(error) 在 Flutter/Dart 中不起作用

这很奇怪..它以前可以工作,现在我收到一个错误,告诉我我的打印语句接受了太多参数。

这是一个典型的例子:

accessDB() async
   {

    try
    {
     io.Directory appDocDir = await getApplicationDocumentsDirectory();
     String databasePath = join(appDocDir.path, kDBName);
     this.db = await openDatabase(databasePath);
     initialized = true;
    }
    catch(error)
     {
       print(error);
       initialized = false;
     }
   }

错误信息是: Too many positional arguments: 0 expected, 1 found.

但 print 语句无论如何都会接受 1 个参数:print(error)

【问题讨论】:

    标签: flutter dart


    【解决方案1】:

    这是我的第一篇文章,我找到了答案。这很奇怪。

    我的 try/catch 在 catch 中都有 print(error) 或 print(e) 输出。他们停止了工作。

    原因?在一个类中的一个函数中,我有一个空的打印语句:

    打印();

    我删除了,现在没有问题了。

    【讨论】:

    • 你能提供一个可重现的例子吗?这似乎非常可疑。我认为您更有可能不小心定义了自己的 print 函数,该函数接受 0 个参数。
    猜你喜欢
    • 2017-03-04
    • 1970-01-01
    • 1970-01-01
    • 2021-09-19
    • 2012-07-01
    • 2021-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多