找不到符号错误

时间:2011-04-28 18:16:58

标签: java compiler-errors

提前感谢您帮助解决我似乎遇到的这个相对简单(我希望)的问题。每当我尝试编译我的编程任务时,我都会遇到“无法找到符号错误”。我指出代码本身发生错误的位置。再次感谢!

    public class SSN
{
    private int one;
    private int two;
    private int three;

    public SSN(int first, int second, int third) throws Exception
    {
        if(first > 99 || first < 1 || second > 999 || second < 1 || third > 9999 || third < 1)
        {

        }
        else
        {
            one = first;
            two = second;
            three = third;
        }
    }

    //method that turns ###-##-#### string into 3 int SSN object
    public static SSN valueOf(String ssn)
    {

    String firstpart;
    firstpart = ssn.substring(0, 2);
    String secondpart;
    secondpart = ssn.substring(4, 5);
    String thirdpart;
    thirdpart = ssn.substring(7, 10);

    int One = Integer.parseInt(firstpart);
    int Two = Integer.parseInt(secondpart);
    int Three = Integer.parseInt(thirdpart);

    System.out.println(firstpart);

        //This is where the cannot find symbol error occurs (return SSN(One, Two, Three),                                       //and I am clueless as to why.
        //Any insight as to why this error is occurring would be much appreciated!

    return SSN(One, Two, Three);
    }


    public String toString()
    {
        return one + "-" + two + "-" + three;
    }

}

3 个答案:

答案 0 :(得分:1)

return new SSN(One, Two, Three);
       ^^^

答案 1 :(得分:0)

您正在尝试通过调用构造函数来创建new SSN(...)

答案 2 :(得分:0)

编译器查找名为“SSN”的方法,但没有这样的方法(编译器找不到该符号)您试图创建一个不调用方法的新对象,因此您需要包含{{ 1}}关键字,如Erik和SLaks所说。

new