【问题标题】:how to solve this error in dart language: NoSuchMethodError : method not found: 'readLineSync'如何在 dart 语言中解决此错误:NoSuchMethodError : method not found: 'readLineSync'
【发布时间】:2020-11-01 11:01:53
【问题描述】:

我是 dart 语言的新手,当我想使用“stdin.readLineSync()”为命令行简单数字猜谜游戏获取用户输入时,我收到此错误。 我的代码是:

import 'dart:math';
import 'dart:io';

void main() {
  int guess;
  Random rand = new Random(); //create a random number generator
  int answer = rand.nextInt(100); //gets a random integer from 0 to 99
  do {
    print("Enter your guess:");
    String temp = stdin.readLineSync(); //read in from the keyboard
    guess = int.parse(temp); //convert String to integer
    if (guess < answer) {
      print("Too low!");
    } else if (guess > answer) {
      print("Too high!");
    }
  } while (guess != answer);
  print("You got it!");
}

错误在于这一行:String temp = stdin.readLineSync(); //从键盘读入 我收到了这个通知:

Unhandled exception:
NoSuchMethodError : method not found: 'readLineSync'
Receiver: Instance of '_SocketInputStream@0x1da10ec4'
Arguments: []
#0      Object._noSuchMethod (dart:core-patch:1360:3)
#1      Object.noSuchMethod (dart:core-patch:1361:25)

【问题讨论】:

  • 你是如何运行你的程序的,你使用的是什么 Dart 版本?
  • 我正在使用 dart 编辑器:Dart Editor 版本 0.2.10_r16761 Dart SDK 版本 0.2.10.1_r16761
  • 这是一个非常旧的 Dart 版本,因为 Dart 编辑器很久以前就被删除了。请使用最新版本的 Dart (2.10.3) 并使用 IntelliJ (dart.dev/tools/jetbrains-plugin) 或 VS Code (dart.dev/tools/vs-code)。
  • 感谢@julemand101。我很困惑。

标签: dart input stdin readline nosuchmethoderror


【解决方案1】:

这是您使用的非常旧的 Dart 版本,因为 Dart 编辑器很久以前就被删除了。请使用最新版本的 Dart (2.10.3) 并使用 IntelliJ (dart.dev/tools/jetbrains-plugin) 或 VS Code (dart.dev/tools/vs-code)。 感谢@julemand101。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-05-12
    • 2019-12-17
    • 1970-01-01
    • 2021-03-04
    • 1970-01-01
    • 2012-01-29
    • 1970-01-01
    相关资源
    最近更新 更多