Java中的“错误:找不到符号”是什么意思?

时间:2020-05-02 20:31:25

标签: java inheritance compilation symbols abstract

在Eclipse中成功创建并运行了一个简单的Java App之后,我将源文件复制到了一个单独的文件夹中,并使用javac * .java进行了编译,然后使用java cardealership.java命令启动了主类。我收到错误消息:

symbol:   class bicycle
location: class cardealership
cardealership.java:47: error: cannot find symbol
                    bicycle b = new bicycle();

car.java:

软件包nos.lab2;

public  class car extends vehicle {
  car(){
    type = "car";
    driveable = true;
  }
  }

cardealership.java

package nos.lab2;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import nos.lab2.*;


public class cardealership {

List<vehicle> vehicles_history = new ArrayList<vehicle>();
List<vehicle> vehicles = new ArrayList<vehicle>();
List<owner> owners = new ArrayList<owner>();

public static void main(String[] args) {
    cardealership cardealership = new cardealership();
    cardealership.start();

}

  public void start() {
        Scanner in = new Scanner(System.in);
        int i = 1;
        int j = 1;

        do{
            System.out.println();
            System.out.println("1. Add vehicle\n3. Add sale\n4. Show history\n5. Show the state of the warehouse\n0. Exit\n");
            i = in.nextInt();

            switch (i) {
            case 1:
                System.out.println("1. Car\n2. Truck\n3. Bicycle\n4. Motorcycle\n5. Trailer\n6. Back\n");
                j = in.nextInt();
                switch (j) {
                case 1:
                    car c = new car();
                    vehicles.add(c);
                    System.out.println("\nCar with id " + c.id+ " added\n");
                    break;
                case 2:
                    truck t = new truck();
                    vehicles.add(t);
                    System.out.println("\nTruck with id " + t.id+ " added\n");
                    break;
                case 3:
                    bicycle b = new bicycle();
                    vehicles.add(b);
                    System.out.println("\nBicycle with id " + b.id+ " added\n");
                    break;
                case 4:
                    motorcycle m = new motorcycle();
                    vehicles.add(m);
                    System.out.println("\nMotorcycle with id " + m.id+ " added\n");
                    break;
                case 5:
                    trailer tr = new trailer();
                    vehicles.add(tr);
                    System.out.println("\nTrailer with id " + tr.id+ " added\n");
                    break;
                case 6:
                    break;

                };
                break;
            case 3:
                System.out.println("Id of vehicle to be sold \n");
                int id = in.nextInt();

                for (int z = 0; z < vehicles.size(); z++) {

                    if (vehicles.get(z).id == id ) {
                        vehicles_history.add(vehicles.get(z));
                        vehicles.remove(z);


                        System.out.println("Name\n");
                        String name = in.nextLine();

                        System.out.println("Birthdate\n");
                        String birthdate = in.nextLine();

                        System.out.println("Address\n");
                        String address = in.nextLine();

                        owner o = new owner(name, birthdate, address);
                        owners.add(o);
                        System.out.println("Owner " + name + " added\n");

                        break;
                    }

                }

                break;
            case 4:
                for (int z = 0; z < vehicles_history.size(); z++) {
                    System.out.println(vehicles_history.get(z).id + " " + vehicles_history.get(z).type + "\n");

                }
                break;
            case 5:
                for (int z = 0; z < vehicles.size(); z++) {
                    System.out.println(vehicles.get(z).id + " " + vehicles.get(z).type + "\n");

                }
                break;
            case 0:

                break;
            default:

                break;
            };

        } while(i != 0);
    }
}

对于其余类(如卡车或拖车),将出现相同的错误(“找不到符号”)。任何想法如何解决这个问题?谢谢!

0 个答案:

没有答案