Java 关于字符串检查的if语句中无法访问的代码

Java 关于字符串检查的if语句中无法访问的代码,java,if-statement,unreachable-code,Java,If Statement,Unreachable Code,由于某种原因,我得到一个错误,行currentUser=gar.getAccountuserN;是不可接近的,但它不应该是。Garage.getAccount只是从Hashmap中检索。两个if语句都不相互对抗,我也尝试过添加else语句,但不管它说什么,这行都是不可访问的 package main; import java.util.Scanner; public class Main { private static Scanner input; private sta

由于某种原因,我得到一个错误,行currentUser=gar.getAccountuserN;是不可接近的,但它不应该是。Garage.getAccount只是从Hashmap中检索。两个if语句都不相互对抗,我也尝试过添加else语句,但不管它说什么,这行都是不可访问的

package main;

import java.util.Scanner;

public class Main {

    private static Scanner input;
    private static Garage gar;
    private static Attendant currentUser;
    private static boolean isManager;

    public static void main(String[] args) {
        input = new Scanner(System.in);
        gar = new Garage(10, 80, 10);
        currentUser = null;
        while (currentUser == null)
            logIn();
    }

    public static void logIn() {
        System.out.println("Enter username: ");
        String userN = input.nextLine();
        System.out.println("Enter password:");
        String userP = input.nextLine();
        //if no username, go back
        if(gar.getAccount(userN) == null) { 
            error("Incorrect username");
            return;
        } 
        if(gar.getAccount(userN).getPassword().equals(userP) == false); { //if entered password doesn't match
            error("Incorrect password");
            return;
        } 
        currentUser = gar.getAccount(userN);
        return;
    }

    //update to throw error pop-up later
    public static void error(String er) { System.out.println(er); }
}

您的语法不正确,if语句的条件不应以分号结尾

 package main;

    import java.util.Scanner;

    public class Main {

        private static Scanner input;
        private static Garage gar;
        private static Attendant currentUser;
        private static boolean isManager;

        public static void main(String[] args) {
            input = new Scanner(System.in);
            gar = new Garage(10, 80, 10);
            currentUser = null;
            while (currentUser == null)
                logIn();
        }

        public static void logIn() {
            System.out.println("Enter username: ");
            String userN = input.nextLine();
            System.out.println("Enter password:");
            String userP = input.nextLine();
            //if no username, go back
            if(gar.getAccount(userN) == null) { 
                error("Incorrect username");
                return;
            } 
            if(gar.getAccount(userN).getPassword().equals(userP) == false) { //if entered password doesn't match
                error("Incorrect password");
                return;
            } 
            currentUser = gar.getAccount(userN);
            return;
        }

        //update to throw error pop-up later
        public static void error(String er) { System.out.println(er); }
    }
ifgar.getAccountuserN.getPassword.equalsuserP==false;分号终止if体。移除它。投票以打字错误结束。