Unresolved compilation problem: username cannot be resolved to a variable
import java.util.*; import java.io.*; import java.math.*; public class Welcome { public static void main(String[] args) { Console cons = System.console(); username = cons.readLine("%s","Username:"); char[] password = cons.readPassword("%s","Password:"); } }
这段代码为什么在eclipse下编会报错,而在命令行模式下没有问题? eclipse 报错如下: Exception in thread "main" java.lang.Error: Unresolved compilation problem: username cannot be resolved to a variable
at Welcome.main(Welcome.java:18)
Console cons = System.console(); if(cons != null){ String username = cons.readLine("%s","Username:"); char[] password = cons.readPassword("%s","Password:"); } 错误在于 username 前面没有类型String。
eclipse使用自有的编译器ecj。
Eclipse的Console不是System.console()
|