Click here to Skip to main content
14,451,737 members
Rate this:
Please Sign up or sign in to vote.
Good morning,

I have been working on a project for the last few weeks, and I cant seem to figure out what I am doing wrong. When I run the java files, it will not find the Displayable class. This is not the only file in the util package, and yet it is the only one it will not find. I am new to JAVA, and this is my first project.

I am also new to this site. I don't see where I can upload files. Here is what I have copied from DOS Shell for the error messages for each of the classes.

C:\Users\moga2\Desktop\Webucator\Project Directory>javac PrintReports.java
.\util\Displayable.java:3: error: class, interface, or enum expected
public abstract String display() {
                ^
PrintReports.java:7: error: cannot access Displayable
    ArrayList<Displayable> classroomList = new ArrayList<>();
              ^
  bad source file: .\util\Displayable.java
    file does not contain class util.Displayable
    Please remove or make sure it appears in the correct subdirectory of the sourcepath.


C:\Users\moga2\Desktop\Webucator\Project Directory\school>javac Classroom.java Classroom.java:2: error: package util does not exist
import util.Displayable;
           ^
Classroom.java:6: error: cannot find symbol
public class Classroom implements Displayable {
                                  ^
  symbol: class Displayable
Classroom.java:9: error: cannot find symbol
    private Displayable teacher;
            ^
  symbol:   class Displayable
  location: class Classroom
Classroom.java:10: error: cannot find symbol
    private ArrayList<Displayable> students;
                      ^
  symbol:   class Displayable
  location: class Classroom
Classroom.java:15: error: cannot find symbol
    public Classroom(int roomNumber, Displayable teacher, ArrayList<Displayable> students) {
                                     ^
  symbol:   class Displayable
  location: class Classroom
Classroom.java:15: error: cannot find symbol
    public Classroom(int roomNumber, Displayable teacher, ArrayList<Displayable> students) {
                                                                    ^
  symbol:   class Displayable
  location: class Classroom
Classroom.java:29: error: cannot find symbol
    public Displayable getTeacher() {
           ^
  symbol:   class Displayable
  location: class Classroom
Classroom.java:33: error: cannot find symbol
    public void setTeacher(Displayable teacher) {
                           ^
  symbol:   class Displayable
  location: class Classroom
Classroom.java:37: error: cannot find symbol
    public ArrayList<Displayable> getStudents() {
                     ^
  symbol:   class Displayable
  location: class Classroom
Classroom.java:41: error: cannot find symbol
    public void setStudents(ArrayList<Displayable> students) {
                                      ^
  symbol:   class Displayable
  location: class Classroom
Classroom.java:45: error: method does not override or implement a method from a supertype
    @Override
    ^
Classroom.java:50: error: cannot find symbol
        ArrayList<Displayable> studentList = this.getStudents();
                  ^
  symbol:   class Displayable
  location: class Classroom
12 errors


C:\Users\moga2\Desktop\Webucator\Project Directory\school>javac Student.java
Student.java:2: error: package util does not exist
import util.Displayable;
           ^
Student.java:4: error: cannot find symbol
public class Student extends Person implements Displayable {
                             ^
  symbol: class Person
Student.java:4: error: cannot find symbol
public class Student extends Person implements Displayable {
                                               ^
  symbol: class Displayable
Student.java:13: error: cannot find symbol
        this.setFirstName(firstName);
            ^
  symbol: method setFirstName(String)
Student.java:14: error: cannot find symbol
        this.setLastName(lastName);
            ^
  symbol: method setLastName(String)
Student.java:35: error: method does not override or implement a method from a supertype
    @Override
    ^
Student.java:37: error: cannot find symbol
        return "Student ID: " + this.getStudentId() + "    " + this.getFullName() + " Final Grade: " + this.getFinalGrade();
                                                                   ^
  symbol: method getFullName()
7 errors


C:\Users\moga2\Desktop\Webucator\Project Directory\school>javac Teacher.java
Teacher.java:2: error: package util does not exist
import util.Displayable;
           ^
Teacher.java:4: error: cannot find symbol
public class Teacher extends Person implements Displayable {
                             ^
  symbol: class Person
Teacher.java:4: error: cannot find symbol
public class Teacher extends Person implements Displayable {
                                               ^
  symbol: class Displayable
Teacher.java:11: error: cannot find symbol
    this.setFirstName(firstName);
        ^
  symbol: method setFirstName(String)
Teacher.java:12: error: cannot find symbol
    this.setLastName(lastName);
        ^
  symbol: method setLastName(String)
Teacher.java:21: error: method does not override or implement a method from a supertype
    @Override
    ^
Teacher.java:23: error: cannot find symbol
            return this.getFullName() + "teaches" + this.getSubject();
                       ^
  symbol: method getFullName()
7 errors


What I have tried:

I have checked the classpath, I have re-created the entire project, and re-installed all software just to be sure.
Posted
Updated 30-Jun-19 0:19am
Comments
Richard MacCutchan 29-Jun-19 13:28pm
   
Something is missing from that file. But since you have not shown the source it is difficult to guess what.
moga2003 29-Jun-19 15:47pm
   
The directions for the Displayable class are below:

In the util package, create the Displayable interface. The interface should declare one method as follows:
public abstract String display()

This is what I have in the Displayable.java file:
package util;

public abstract String display()
phil.o 30-Jun-19 3:15am
   
You cannot declare an abstract element in an interface; interface is abstract by essence already. Try to strip off the abstract keyword from the interface. Later you can declare this function as abstract in an implementing class, but you will have to implement it anyway (i.e., not abstract) at some point.
Richard MacCutchan 30-Jun-19 3:59am
   
You cannot declare a method outside a class or interface.

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

The Displayable.java file needs to define the Displayable interface, in order for the implementing class to import its definitions. Something like:
Package until;
interface Displayable {
    public String display() {
    // other code here
    }
} // end of interface definition


For more information I suggest you google for “The Java Tutorials” and work through them.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100