title: PriorityQueue: Student cannot be cast to java.lang.Comparable
body: <p>I'm using the PriorityQueue structure to get some fields set by the user, here is part of the code:</p>
  
  <pre><code>package gqg;
  
  import java.util.Queue;
  
  public class Student {
       //variables (ID, Name, ...), constructors, getters and setters...
  
  Queue&lt;Student&gt; StudentQueue = new PriorityQueue&lt;Student&gt;();
  
  public void Add() { //method to add the student at Queue
      for(int x=0; x&lt;1; x++) {
          Student st = new Student();
          System.out.println("+---------------------------+\n"
                           + "|   Students Registration   |\n"
                           + "+---------------------------+");
          System.out.println("| Type the student's ID:");
          stu.setID(user.nextInt());
          System.out.println("| Type the student's name:");
          stu.setName(user.next());
          System.out.println("| Type the student's age:");
          stu.setAge(user.nextInt());
          //and other fields...
  
          StudentQueue.add(st);
      }
      System.out.println("Done. Student has been added successfuly\n");       
  }
  
  /* then I call Add(); in Menu();
   * this method also has Print(); Modify(); Eliminate(); those three works well
   * The only one problem is Add();
   */
  
  public void Menu(){
      //... methods
  }
  }
  </code></pre>
  
  <p>There is no problem when I add only one "student", but the application throws this exception when I try to capture a second one</p>
  
  <pre><code>Exception in thread "main" java.lang.ClassCastException: gqg.Student cannot be cast to java.lang.Comparable     at
  java.util.PriorityQueue.siftUpComparable(PriorityQueue.java:633)    at
  java.util.PriorityQueue.siftUp(PriorityQueue.java:629)  at
  java.util.PriorityQueue.offer(PriorityQueue.java:329)   at
  java.util.PriorityQueue.add(PriorityQueue.java:306)     at
  gqg.Student.AddQueue(Student.java:374)  at
  gqg.Student.Menu(Student.java:592)  at
  gqg.MainClass.main(MainClass.java:7)
  </code></pre>
  
  <p>Can someone explain me where/why is the problem? I spent a lot of time looking for a solution in web and I couldn't find it, I need some help here...
  Tank you for helping me</p>