解决代码中的错误

时间:2013-11-09 15:15:22

标签: java swing

我似乎无法弄清楚此代码中的问题。当我试着跑的时候一直说:

Exception in thread "AWT-EventQueue-0" java.lang.Error: Unresolved compilation problems: 
    Syntax error, insert "}" to complete MethodBody
    Syntax error, insert "}" to complete ClassBody

但是当我尝试将}添加到代码时,它仍然无法解决错误。

这是代码:

public String checkPostalCode (String state, int postalno) {

     String postalno1 = Integer.toString(postalno);
String result = "";

String BELAIT = "^[3000-3999](1,4}$";
String TUTONG = "^[2600-2618][2900-2920]{1,4}$";
String BANDAR = "^[2000-2599][2619-2898][2921-2999]{1,4}$";
String TEMBURONG = "^[4000-4999]{1,4}$";


if(state == "Belait") {
    Pattern chckPostalCode = Pattern.compile(BELAIT);
    Matcher chckPostalCodematcher=chckPostalCode.matcher(postalno1);

    boolean Belait = chckPostalCodematcher.matches();
    if(Belait==true){
        result = "pass";
}
    else{
        result = "fail";
    }
    if(state == "Tutong") {
        Pattern chckPostalCode1 = Pattern.compile(TUTONG);
        Matcher chckPostalCodematcher1=chckPostalCode.matcher(postalno1);

        boolean Tutong = chckPostalCodematcher.matches();
        if(Tutong==true){
            result = "pass";
    }
    else{
        result = "fail";
    }

    if(state == "Bandar Seri Begawan") {
        Pattern chckPostalCode2 = Pattern.compile(BANDAR);
        Matcher chckPostalCodematcher2=chckPostalCode.matcher(postalno1);

        boolean Bandar = chckPostalCodematcher.matches();
        if(Bandar==true){
            result="pass";
    }
    else{
        result = "fail";
    }

        if(state == "Temburong") {
            Pattern chckPostalCode3 = Pattern.compile(TEMBURONG);
            Matcher chckPostalCodematcher3=chckPostalCode.matcher(postalno1);

            boolean Temburong = chckPostalCodematcher.matches();
            if(Temburong==true){
                result="pass";
        }
        else{
            result = "fail";
        }


return result;

 }

    }
return result;
}
}
 }))

1 个答案:

答案 0 :(得分:1)

你忘了关闭括号:

if(Belait==true){
    result = "pass";
} // you forgot this

同样适用于if(Tutong==true)if(Bandar==true)等。

始终使用IDE来避免这些类型的拼写错误。