2011-04-28 151 views
0

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

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; 
    } 

} 

回答

0

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

1
return new SSN(One, Two, Three); 
     ^^^ 
+0

啊..我现在觉得很愚蠢。感谢一帮帮忙! – xlnc 2011-04-28 18:22:23

0

编译器SI寻找一个名为“SSN”的方法,但没有这样的方法(编译器不能找到符号)你正在尝试创建一个新的对象不调用一个方法因而需要包括Erik和SLaks说的new关键字。

return new SSN(One, Two, Three);