简单的java问题。
class Check{
public boolean validate(String name,String password){
if(name.equals("li")&&password.equals(123456)){
return true;
}
else{
return false;
}
}
}
class Operate{
private String info[];
public Operate(String info[]){
this.info=info;
}
public String login(){
Check check=new Check();
this.isExit();
String str=null;
String name=this.info[0];
String password=this.info[1];
if(check.validate(name, password)){
str="欢迎"+name+"光临!";
}
else{
str="错误的用户名和密码!";
}
return str;
}
public void isExit(){
if(this.info.length!=2){
System.out.print("输入的参数不正确,系统退出!");
System.out.print("格式:java LoginDemo1 用户名 密码");
System.exit(1);
}
}
}
public class Demo3 {
public static void main(String args[]){
Operate oper=new Operate(args);
System.out.println(oper.login());
}
}
编译的时候没有错,但是在运行的时候就会出现exception in thread "main"java.lang.nosuchmethoderror:main
这是为什么呢。。
[解决办法]
估计是jdk问题。用eclipse有时也出现这个问题。
[解决办法]
我跑了一下,我的机器上是可以跑的啊,楼主是不是其他什么问题啊,比如说jdk啊,就像一楼说的,我跑的命令如下:
F:\javaspace\com\csdn>javac Demo3.java
F:\javaspace\com\csdn>java Demo3
输入的参数不正确,系统退出!格式:java LoginDemo1 用户名 密码
[解决办法]
class Check { public boolean validate(String name, String password) { if (name.equals("li") && password.equals("123456")) {//"123456"而不是123456 return true; } else { return false; } }}class Operate { private String info[]; public Operate(String info[]) { this.info = info; } public String login() { Check check = new Check(); this.isExit(); String str = null; String name = this.info[0]; String password = this.info[1]; if (check.validate(name, password)) { str = "欢迎" + name + "光临!"; } else { str = "错误的用户名和密码!"; } return str; } public void isExit() { if (this.info.length != 2) { System.out.print("输入的参数不正确,系统退出!"); System.out.print("格式:java LoginDemo1 用户名 密码"); System.exit(1); } }}public class Demo3 { public static void main(String args[]) { String[] temp = new String[2]; temp[0] = "li"; temp[1] = "123456"; //Operate oper = new Operate(args); Operate oper = new Operate(temp); System.out.println(oper.login()); }}/*你的密码是字符串呀,为什么你写成123456呢 少了双引号吧 重新运行改写后的程序 看能否出现下面结果,欢迎li光临!*/