title: How to fix a ClassCastExecption, and a NullPointerException?
body: <p>I'm writing some code for a project for my intro to OOP course. The program is to write a report based on some courses inputted by the user.  My test class looks like this</p>
  
  <pre><code>    import java.util.*;
      public class CourseReport {
      private ArrayList&lt;Showable&gt; courses = new ArrayList&lt;Showable&gt;();
      ArrayList&lt;Showable&gt; students = new ArrayList&lt;Showable&gt;();
      Scanner keyboard = new Scanner(System.in);
      public CourseReport() {
          char cont = 'y';
          while(cont == 'y') {
              courses.add(addCourse());
              System.out.println("Need to enter another course? (y.n)");
              cont = keyboard.next().charAt(0);
          }
      }
      public Showable addCourse() {
          System.out.println("Please enter the Course ID: ");
          int courseID = keyboard.nextInt();
          while((courseID &lt; 200) || (courseID &gt;= 300)) {
              System.out.println("Invaild course ID");
              courseID = keyboard.nextInt();
          }
          Showable instructor = addInstructor();
          char cont = 'y';
          while(cont == 'y') {
              students.add(addStudent());
              System.out.println("Need to enter another student? (y,n)");
              cont = keyboard.next().charAt(0);
          }
          Showable course = (Showable) new Course(courseID, instructor, 
          students);
          return course;
      }
      public Showable addStudent() {
          System.out.println("Please input the Student ID: ");
          int studentID = keyboard.nextInt();
          while (studentID &lt; 0) {
              System.out.println("Invalid ID number, try again");
              studentID = keyboard.nextInt();
          }
          System.out.println("Please input the first name of the student");
          keyboard.nextLine();
          String firstName = keyboard.nextLine();
          System.out.println("Please input the last name of the student");
          String lastName = keyboard.nextLine();
          System.out.println("Please input the grade of the student");
          int grade = keyboard.nextInt();
          while ((grade &gt; 100) || (grade &lt;= 35)) {
              System.out.println("Invalid grade, try again");
              grade = keyboard.nextInt();
          }
          Showable student = new Student(firstName, lastName, studentID, grade);
          return student;
      }
      public Showable addInstructor() {
          System.out.println("Please input the first name of the professor");
          String firstName = keyboard.nextLine();
          System.out.println("Please input the last name of the professor");
          String lastName = keyboard.nextLine();
          System.out.println("Please input the statues of the professor");
          String statues = keyboard.nextLine();
          Showable instructor = new Instructor(firstName, lastName, statues);
          return instructor;
      }
      public void printReport() {
          Showable course;
  
          for(int i = 0; i &lt; courses.size(); i++) {
              course = courses.get(i);
              course.show();
              ((Course) course).getInstructor().show();
              for(int j = 0; j &lt; students.size(); j++) {
                  ((Course) course).getStudents().get(j);
          }
          }
      }
      public static void main(String[] args) {
          CourseReport course = new CourseReport();
          course.printReport();
      }
      }
  </code></pre>
  
  <p>The line <code>Showable course = (Showable) new Course(courseID, instructor, students);</code> is giving me a ClassCastException by telling be that Course cannot be casted to Showable.  Showable is an interface with the method show.  The class Course looks like this</p>
  
  <pre><code>import java.util.*;
  public class Course {
      private int courseID;
      private Showable instructor;
      private ArrayList&lt;Showable&gt; students = new ArrayList&lt;Showable&gt;();
      public int getCourseID() {
          return courseID;
      }
      public Showable getInstructor() {
          return instructor;
      }
      public void setCourseID(int courseID) {
          courseID = this.courseID;
      }
      public void setInstructor(Showable instructor) {
          instructor = this.instructor;
      }
      public void setStudents(ArrayList&lt;Showable&gt; students) {
          this.students = students;
      }
      public ArrayList&lt;Showable&gt; getStudents() {
          return students;
      }
  
      public Course() {
      }
      public Course(int courseID, Showable instructor, ArrayList&lt;Showable&gt; students) {
          courseID = this.courseID;
          instructor = this.instructor;
          students = this.students;
      }
      public String show() {
          return "courseID is: " + courseID;
      }
  }
  </code></pre>
  
  <p>Also would anyone know why my inner for loop in the PrintReport method would throw a NullPointerExeception?</p>
  
  <pre><code>public void printReport() {
          Showable course;
  
          for(int i = 0; i &lt; courses.size(); i++) {
              course = courses.get(i);
              course.show();
              ((Course) course).getInstructor().show();
              for(int j = 0; j &lt; students.size(); j++) {
                  ((Course) course).getStudents().get(j);
          }
          }
      }
  </code></pre>