1

Deleted by request of academic institution I am unable to provide examples

2 Answers2

0

This is the important error message.

Cannot make a static reference to the non-static method getStudentID(); from the type Student.

You need to call getStudentID() on an instance of the class, and not the class itself. You can try something like this.

public static void print_all() {

    System.out.println("Student ID\tRecent Grades\tName\t\tE-Mail\t\t\tAge");
    for (Student w : studentlist) {
        System.out.print(w.getStudentID() + "\t\t");
        System.out.print(w.getGrades() + "\t");
        System.out.print(w.getFirstname()+ " ");
        System.out.print(w.getLastname()+ "\t");
        System.out.print(w.getEmail()+ "\t");
        System.out.print(w.getAge()+ "\t");
        System.out.println(" ");
    }
}

Calling Student.getStudentID() would only work if there was a static (shared) ID for all the students. This is not the case here. You can look at this post for a more complete explanation of the static keyword in java.

Community
  • 1
  • 1
Boo Radley
  • 676
  • 1
  • 11
  • 24
  • It turns out I was using the arraylist studentlist so i needed to do a get().getStudentID() in order to properly call my values. – GrumpyCoder Jun 28 '16 at 17:09
  • @GrumpyCoder You don't *need* to use `get(i).getX()` if you use a `for-each` loop. I updated my answer to provide an alternative to your solution. – Boo Radley Jun 28 '16 at 17:18
  • I like this better than the get and getID I was using, much cleaner. I wanted to hold onto the advanced for loop as well, instead of the counter based loop, I think they're a lot cleaner. – GrumpyCoder Jun 28 '16 at 17:44
0

The error says it all. The method getStudentID() is a non-static method of the Student class. The call Student.getStudentID() is a static call and hence the error. Invoke the method getStudentID() on an instance of a Student.

toro
  • 184
  • 5