how to solve this error in dart language: NoSuchMethodError : method not found: 'readLineSync'
how to solve this error in dart language: NoSuchMethodError : method not found: 'readLineSync'
我是 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 (2.10.3) 并使用 IntelliJ (dart.dev/tools/jetbrains-plugin) 或 VS Code (dart.dev/tools/vs-code)。
感谢@julemand101。
我是 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 (2.10.3) 并使用 IntelliJ (dart.dev/tools/jetbrains-plugin) 或 VS Code (dart.dev/tools/vs-code)。 感谢@julemand101。