Results 1 to 6 of 6
  1. #1
    star12345645 is offline Member
    Join Date
    Dec 2011
    Posts
    3
    Rep Power
    0

    Default Grade Book class, please help

    I have to do a multiclass program and there's a logic error that I can't figure out.

    public void inputStudents() throws FileNotFoundException //This will work to interactively input Students
    {

    Scanner inF = new Scanner(new File("C:\\Users\\Caili\\Documents\\Sophmore\\AP Computer Science\\Unit 4\\TextFile.txt"));
    while(inF.hasNextLine( ))
    {

    Student aStudent = new Student();

    aStudent.inputInfo("Name",inF.nextLine( ));
    aStudent.inputInfo("Tests",inF.nextLine( ));
    aStudent.inputInfo("Programs",inF.nextLine( ));
    aStudent.inputInfo("Homework",inF.nextLine( ));

    aStudent.computeAve();
    aStudent.computeGrade();
    myStudents.add(aStudent); It says that this line is null when I try to run it.

    }

    I have this that goes along with the method

    public void inputInfo(String scoresType,String info)
    {
    if(scoresType.equals("Name"))
    myName = info;
    else if(scoresType.equals("Tests"))
    myTests.getScores(info);
    else if(scoresType.equals("Programs"))
    myProgs.getScores(info);
    else if(scoresType.equals("Homework"))
    myHk.getScores(info);
    }


    public void getScores(String lineNumbers) //Interactively read scores from the keyboard into an array (-999 terminates input)
    {
    Scanner lineScan = new Scanner(lineNumbers);
    while(lineScan.hasNext())
    {
    int num = lineScan.nextInt();
    myScores[mySize] = num;
    mySize++;
    }
    }

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,332
    Rep Power
    25

    Default Re: Grade Book class, please help

    Does the variable myStudents have a valid value or is its value null?

    Where do you define it and where do you give it a value?

  3. #3
    star12345645 is offline Member
    Join Date
    Dec 2011
    Posts
    3
    Rep Power
    0

    Default Re: Grade Book class, please help

    I declare it in the constucter
    public ClassList()
    {
    ArrayList<Student> myStudents = new ArrayList<Student>();
    int[] myGradeDistribution = new int[GREATEST_SIZE];
    count = 0;
    scoreSum = 0;
    additional = 0;
    }

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,332
    Rep Power
    25

    Default Re: Grade Book class, please help

    myStudents.add(aStudent); It says that this line is null
    Please post the full text of the error message. Your edited version is leaving off valuable information.

  5. #5
    star12345645 is offline Member
    Join Date
    Dec 2011
    Posts
    3
    Rep Power
    0

    Default Re: Grade Book class, please help

    in the Classlist class it says :java.lang.NullPointerException: null
    Last edited by star12345645; 12-11-2011 at 02:42 AM.

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,332
    Rep Power
    25

    Default Re: Grade Book class, please help

    Please post the FULL text of the error message. Your edited version is leaving off important information.

Similar Threads

  1. Urgent help! npassing and highest grade
    By aznlnja in forum New To Java
    Replies: 1
    Last Post: 10-13-2011, 10:30 AM
  2. Help with calculation for final grade of student
    By Braxtonmj in forum New To Java
    Replies: 7
    Last Post: 05-10-2010, 11:49 PM
  3. Array highest grade
    By Cdlove in forum New To Java
    Replies: 5
    Last Post: 05-05-2010, 09:25 PM
  4. Grade my questions, lol
    By syntrax in forum New To Java
    Replies: 4
    Last Post: 12-16-2009, 06:03 AM
  5. Help with JAVA (Grade Book)
    By Sara_21 in forum New To Java
    Replies: 3
    Last Post: 11-30-2009, 02:45 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •