方法 nextline() 未为类型 Scanner 定义
The method nextline() is undefined for the type Scanner
我正在努力理解它的含义以及它为什么是错误的。
import java.util.Scanner;
public class Relevent {
public static void main(String[]args){
Scanner x = new Scanner(System.in);
System.out.println( x.nextline());
}
}
Eclipse IDE 告诉我这是错误的并给出此消息:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method nextline() is undefined for the type Scanner
at Relevent.main(Relevent.java:9)
写x.nextLine()
怎么样? Java 是区分大小写的语言。
您必须完全按照那里写的 API 进行操作。
方法名称 nextline
看起来不像 understandable/obvious,不是吗?因此,Java 编程的最佳实践是以驼峰式大小写所有名称(final
和 static
变量除外,例如 MY_FINAL_VARIABLE
)。
该方法称为 nextLine
(注意大写 L)而不是 nextline
(全部小写)。一定要注意方法名之类的大小写,一定要完全正确。
Eclipse 显示您有编译错误。如果您尝试 运行 包含编译错误的程序,它将失败并显示您收到的 'Unresolved compilation problem:' 消息。
我正在努力理解它的含义以及它为什么是错误的。
import java.util.Scanner;
public class Relevent {
public static void main(String[]args){
Scanner x = new Scanner(System.in);
System.out.println( x.nextline());
}
}
Eclipse IDE 告诉我这是错误的并给出此消息:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method nextline() is undefined for the type Scanner
at Relevent.main(Relevent.java:9)
写x.nextLine()
怎么样? Java 是区分大小写的语言。
您必须完全按照那里写的 API 进行操作。
方法名称 nextline
看起来不像 understandable/obvious,不是吗?因此,Java 编程的最佳实践是以驼峰式大小写所有名称(final
和 static
变量除外,例如 MY_FINAL_VARIABLE
)。
该方法称为 nextLine
(注意大写 L)而不是 nextline
(全部小写)。一定要注意方法名之类的大小写,一定要完全正确。
Eclipse 显示您有编译错误。如果您尝试 运行 包含编译错误的程序,它将失败并显示您收到的 'Unresolved compilation problem:' 消息。