您的位置:首页 > 编程语言 > Java开发

关于Eclipse中遇到的经常性参数报错问题总结

2016-07-29 15:43 369 查看

菜鸟第一次写博客来记录一下遇到的问题,粘贴部分有代表性的代码来说明错误即可。
  在java学习过程中,学习到输入username和password时,出于对password的安全性考虑使用Console类

import java.io.Console;
import java.util.*;

public class InputTest {
public static void main(String[] args){
System.out.printf("%tc",new Date());//打印当前日期
Console console = System.console();
char[] password = console.readPassword("Password: ");//获取password


却发现如下错误

  The method readPassword() in the type Console is not applicable for the arguments (String)

    

  在格式打印当前日期时

  The method printf(String, Object[]) in the type PrintStream is not applicable for the arguments (String, Date)

  (偏题一下,在其他文章中得到关于console的问题)Javaw所执行的应用程式(eclipse)没有主控制台(console),所以取不到console物件,System.console()只能是null了。用终端运行代码也确实没问题。

那么为什么这里会报错呢,答案是java compiler的版本问题。找到对应项目的properties->选择Java Compiler->选择 Compiler compliance level->设置为1.5
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  eclipse java 参数问题