日期:2014-05-20  浏览次数:21159 次

true和false无法作为返回变量的解决方案?
在做JavaKe的项目。遇到一点问题,问问有经验的大家,打扰了
部分代码是:
public static boolean checkLogin(UserInfo user){
if(userDB.containsKey(user.getName())){  
return ture;
}
System.out.println("Fail in Check!: "+user.getName());
return false;
  }
作为查找服务端有没有该用户名,如果有,那么返回true;
private void processSocket(){
  try{java.io.InputStream ins = client.getInputStream();
  ous = client.getOutputStream();
  BufferedReader brd = new BufferedReader(new InputStreamReader(ins));
  sendMsg2Me("Welcome!Please type in your username: ");
  String userName = brd.readLine();
  sendMsg2Me("Please type in your password: ");
  String pwd = brd.readLine();
  user = new UserInfo();
  user.setName(userName);
  user.setPwd(pwd);
  boolean loginState = DaoTools.checkLogin(user);
  if(!loginState){
  sendMsg2Me("Invalid Input!");
  this.closeMe();
  return;
  }
  else{
  ChatTools.addClient(this);
  String input = brd.readLine();
  while(!"bye".equals(input)){
  System.out.println("The Server Received: "+ input);
  ChatTools.castMsg(this.user, input);
  input = brd.readLine();
  }}
  }catch(Exception ef){ef.printStackTrace();}
  ChatTools.castMsg(this.user, "I am OffLine.Bye!");
  this.closeMe();
  }

错误log:

Exception in thread "Thread-0" java.lang.Error: Unresolved compilation problem: 
ture cannot be resolved to a variable

at DaoTools.checkLogin(DaoTools.java:5)
at ServerThread.processSocket(ServerThread.java:39)
at ServerThread.run(ServerThread.java:19)


------解决方案--------------------
ture cannot be resolved to a variable


true