Java 找不到符号错误
提前感谢您帮助我解决这个我似乎遇到的相对简单(我希望如此)的问题。每当我试图编译我的编程任务时,我都会遇到“找不到符号错误”。我指出错误发生在代码本身的地方。再次感谢Java 找不到符号错误,java,compiler-errors,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 {
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;
}
}
公共类SSN
{
私人int one;
二等兵;
三等兵;
公共SSN(int-first、int-second、int-third)引发异常
{
如果(第一次>99 | |第一次<1 | |第二次>999 | |第二次<1 | |第三次>9999 | |第三次<1)
{
}
其他的
{
一=第一;
二=秒;
三等于三;
}
}
//方法,该方法将####-#-#-####字符串转换为3 int SSN对象
公共静态SSN值(字符串SSN)
{
第一部分;
第一部分=ssn子串(0,2);
第二部分;
第二部分=ssn子串(4,5);
第三部分;
第三部分=ssn子串(7,10);
int One=Integer.parseInt(第一部分);
int Two=整数.parseInt(第二部分);
int三=整数.parseInt(第三部分);
系统输出打印项次(第一部分);
//这就是发生找不到符号错误的地方(返回SSN(1,2,3),//我不知道为什么。
//如能了解此错误发生的原因,将不胜感激!
返回SSN(一、二、三);
}
公共字符串toString()
{
返回1+“-”+2+“-”+3;
}
}
您正试图通过调用构造函数来创建一个新的SSN(…)
。编译器正在寻找一个名为“SSN”的方法,但没有这样的方法(编译器找不到该符号)正如Erik和SLaks所说,您试图创建一个不调用方法的新对象,因此需要输入new
关键字
return new SSN(One, Two, Three);
^^^
return new SSN( One, Two, Three );