找不到符号 - 方法参数

时间:2013-12-11 18:14:10

标签: java methods

当你看标题时看起来像一个毫无意义的帖子,但我已经在寻找一个没有运气的解决方案几个小时了,也许屏幕让我眼花缭乱-_-

无论如何,特定类的重载构造函数给我一个“找不到符号”编译器错误,我不知道为什么。导致我的问题的代码是: -

public Student(String fname, String sname, int age, string ID, String avgGradeStr, String projectedGradeStr, String progTitle, int avgGradeInt, int projectedGradeInt, int progID, double attendance)

,错误源自"int avgGradeInt"参数。

不要用代码轰炸你,完整的类如下,如果需要,我也可以发布Person类。

package DoC;
import java.util.*;

class Student extends Person
{

    protected String avgGradeStr, projectedGradeStr, progTitle;
    protected int avgGradeInt, projectedGradeInt, progID;
    protected double attendance;

    //CONSTRUCTOR
    public Student()
    {
        fname="Not";
        sname="Set";
        avgGradeStr="Not Set";
        ID="Not Set";
        projectedGradeStr="Not Set";
        progTitle="Not Set";

        avgGradeInt=0;
        projectedGradeInt=0;
        progID=0;
        attendance=0;
    }

    //CONSTRUCTOR (OVERLOADED)
    public Student(String fname, String sname, int age, string ID, String avgGradeStr, String projectedGradeStr, String progTitle, int avgGradeInt, int projectedGradeInt, int progID, double attendance)
    {
        fname=this.fname;
        sname=this.sname;
        age=this.age;
        ID=this.ID;
        avgGradeStr=this.avgGradeStr;
        projectedGradeStr=this.projectedGradeStr;
        progTitle=this.progTitle;

        avgGradeInt=this.avgGradeInt;
        projectedGradeInt=this.projectedGradeInt;
        progID=this.progID;
        attendance=this.attendance;
    }

    //GETTERS

    //get average grade string
    protected String getAvgGrade()
    {
        return avgGradeStr;
    }

    //get average grade integer
    protected int getAvgGradeInt()
    {
        return avgGradeInt;
    }

    //get projected grade string
    protected String getProjectedGrade()
    {
        return projectedGradeStr;
    }

    //get projected grade int
    protected int getProjectedGradeInt()
    {
        return projectedGradeInt;
    }

    //get attendance
    protected double getAttendance()
    {
        return attendance;
    }

    //get programme-of-study ID
    protected int getProgrammeID()
    {
        return progID;
    }

    //get programme-of-study title
    protected String getProgrammeTitle()
    {
        return progTitle;
    }
    //END GETTERS

    //START SETTERS

    //set programme id
    protected void setProgrammeID(int progID)
    {
        try{
            progID=this.progID;
        }
        catch(Exception e)
        {
            System.out.println("setProgrammeID() error: " + e);
        }
    }

    //set programme title
    protected void setProgrammeID(String progTitle)
    {
        try{
            progTitle=this.progTitle;
        }
        catch(Exception e)
        {
            System.out.println("setProgrammeTitle() error: " + e);
        }
    }

    //set average grade string
    protected void setAvgGrade(String avgGradeStr)
    {
        try{
            avgGradeStr=this.avgGradeStr;
        }
        catch(Exception e)
        {
            System.out.println("setAvgGrade() error: " +e);
        }
    }

    //set average grade int
    protected void setAvgGradeInt(int avgGradeInt)
    {
        try{
            avgGradeInt=this.avgGradeInt;
        }
        catch(Exception e)
        {
            System.out.println("setAvgGradeInt() error: " +e);
        }
    }

    //set projectede grade string
    protected void setProjectedGrade(String projectedGradeStr)
    {
        try{
            projectedGradeStr=this.projectedGradeStr;
        }
        catch(Exception e)
        {
            System.out.println("setProjectedGrade() error: " +e);
        }
    }

    //set projectede grade int
    protected void setProjectedGradeInt(int projectedGradeInt)
    {
        try{
            projectedGradeInt=this.projectedGradeInt;
        }
        catch(Exception e)
        {
            System.out.println("setProjectedGrade() error: " +e);
        }
    }
    //END SETTERS

} //END CLASS

一如既往,任何帮助都非常感谢大家!

2 个答案:

答案 0 :(得分:4)

string ID应为String ID(Java API中没有string类。

另请注意,您应该在构造函数中交换分配。 你的二传手也一样。

我真的建议你使用IDE(比如Eclipse)。你可以更快地纠正这些错误,而不是在这里询问=)。

答案 1 :(得分:1)

好吧,我发现你有string ID而不是String ID。有时候这样的错误会导致编译器吓坏,并最终在其他地方报告问题。