2011-04-28 183 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);