我正在使用BBEdit,它似乎认为每个'}'放在“你好”之后|| “嗨”如果陈述无法比拟,这显然不是真的。终端也认为这一点,因为它引发了一个关于没有'捕获'的'尝试'的错误。我想知道是否有人有同样的问题和/或知道解决方案?
提前致谢!
class client_handler extends Thread {
private Socket conn;
client_handler(Socket conn) {
this.conn = conn;
}
public void run() {
String line, input="";
String username;
String password;
String UID;
Map<String, String> database_UID = new HashMap<String, String>();
database_UID.put("admin", "1234");
try {
//Fetches the socket reading and writing streams
DataInputStream in = new DataInputStream(conn.getInputStream());
PrintStream out = new PrintStream(conn.getOutputStream());
//Sends a welcome message to new client
out.println("Welcome to the server\nType your username and password like:\nUsername_Password");
//Begins to read input from the client
while((line = in.readLine()) != null && !line.equals(".")) {
//The server replies with the same message
if(line.equalsIgnoreCase("server_quit")) {
//Tells the server the command was given
System.out.println("Given command 'server_quit', closing client connection at "+conn.getPort());
//Tells the user that the server is closing
out.println("Quitting the server...\nHave a nice day!");
conn.close();
}
if(line.equals("admin_"+database_UID.get("admin") {
out.println("Welcome back, Admin!");
}
if(line.equalsIgnoreCase("hello") || line.equalsIgnoreCase("hi")) {
out.println("Good day!");
}
}
System.out.println("Client terminated at "+conn.getPort());
conn.close();
}
catch(IOException e) {
System.out.println("IOException on socket: "+e);
e.printStackTrace();
}
}
答案 0 :(得分:3)
查看上面一行的括号:
if(line.equals("admin_"+database_UID.get("admin") {
3开,1关。那不对。检查此类事物(括号,大括号)时从零开始。添加一个用于打开,减去一个用于关闭。如果你不以零结束,那你就错过了一些(或者如果你最终结果为负数则加了一些)。
答案 1 :(得分:0)
if (line.equals("admin_" + database_UID.get("admin"))) {
最后一个}
答案 2 :(得分:0)
试试这个:
if (line.equals("admin_" + database_UID.get("admin"))) {
而不是
if(line.equals("admin_"+database_UID.get("admin") {