Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Question

Commonmark migration
Source Link

Cannot make a static reference to the non-static field Fleet.fleetList

Cannot make a static reference to the non-static method getBusinessName() from the type Fleet

Cannot make a static reference to the non-static field Fleet.fleetList

Cannot make a static reference to the non-static method getBusinessName() from the type Fleet

Cannot make a static reference to the non-static field Fleet.fleetList

Cannot make a static reference to the non-static method getBusinessName() from the type Fleet

Rollback to Revision 5
Source Link
jackJoe
  • 11.1k
  • 8
  • 54
  • 66

In FleetTUI.java I have a list of Fleets (Each fleet will hold its own list of Trucks).

private static ArrayList<Fleet> fleetCollection;

In Fleet.java, I have a list of Truck objects.

ArrayList<Truck> fleetList;

which gets initialized in it's constructor.

 public Fleet(String businessName){
 this.businessName = businessName;
 this.fleetList = new ArrayList<Truck>();
}

So every time I make a new fleet, I am also making a list of Trucks along with it.

In FleetTUI.java, I have a method that adds a truck to a Fleet, made prior:

 public static void addTruck(){
 printFleets();
 System.out.println("Please enter the fleet number where this truck will be added:");
 inputText = scan.nextLine();
 int inputFleetId = Integer.parseInt(inputText);
 System.out.println("Please enter the truck's horn sound:");
 inputText = scan.nextLine();
 String inputHorn = inputText;
 System.out.println("Please enter the truck's fuel capactity:");
 inputText = scan.nextLine();
 int inputFuelCapacity = Integer.parseInt(inputText);
 System.out.println("Please enter the amount of gas remaining in the tank:");
 double inputGasRemaining = Double.parseDouble(scan.nextLine());
 **Fleet.fleetList**.add(inputFleetId, new Truck(inputHorn, inputFuelCapacity, inputGasRemaining));
 System.out.println("--- A truck that goes " + inputHorn + " with " + inputGasRemaining + " gallon(s) in a " + inputFuelCapacity + " gallon tank has been added to " + **fleetCollection.getBusinessName()** + "'s fleet ---" );
 System.out.println("");
}

I have bolded where I am getting errors. The errors are:

Cannot make a static reference to the non-static field Fleet.fleetList

Cannot make a static reference to the non-static method getBusinessName() from the type Fleet

I don't know any other way to access the list of trucks from inside the fleet I created with the method:

 public static void createFleet(){
 System.out.println("");
 System.out.println("Please enter the name of the fleet.");
 inputText = scan.nextLine();
 
 fleetCollection.add(new Fleet(inputText));
 printFleets();
 System.out.println("");
 System.out.println("--- Fleet: " + inputText + " added ---");
 System.out.println("");
 
}

So I guess really, my question is: How do I correctly add a new Truck into the list of Trucks, which is inside the Fleet I just made using createFleet(), which is housed in it's own collection of fleets?

Update: Thanks :) you guys really helped me! once again!

Update: Thanks :) you guys really helped me! once again!

In FleetTUI.java I have a list of Fleets (Each fleet will hold its own list of Trucks).

private static ArrayList<Fleet> fleetCollection;

In Fleet.java, I have a list of Truck objects.

ArrayList<Truck> fleetList;

which gets initialized in it's constructor.

 public Fleet(String businessName){
 this.businessName = businessName;
 this.fleetList = new ArrayList<Truck>();
}

So every time I make a new fleet, I am also making a list of Trucks along with it.

In FleetTUI.java, I have a method that adds a truck to a Fleet, made prior:

 public static void addTruck(){
 printFleets();
 System.out.println("Please enter the fleet number where this truck will be added:");
 inputText = scan.nextLine();
 int inputFleetId = Integer.parseInt(inputText);
 System.out.println("Please enter the truck's horn sound:");
 inputText = scan.nextLine();
 String inputHorn = inputText;
 System.out.println("Please enter the truck's fuel capactity:");
 inputText = scan.nextLine();
 int inputFuelCapacity = Integer.parseInt(inputText);
 System.out.println("Please enter the amount of gas remaining in the tank:");
 double inputGasRemaining = Double.parseDouble(scan.nextLine());
 **Fleet.fleetList**.add(inputFleetId, new Truck(inputHorn, inputFuelCapacity, inputGasRemaining));
 System.out.println("--- A truck that goes " + inputHorn + " with " + inputGasRemaining + " gallon(s) in a " + inputFuelCapacity + " gallon tank has been added to " + **fleetCollection.getBusinessName()** + "'s fleet ---" );
 System.out.println("");
}

I have bolded where I am getting errors. The errors are:

Cannot make a static reference to the non-static field Fleet.fleetList

Cannot make a static reference to the non-static method getBusinessName() from the type Fleet

I don't know any other way to access the list of trucks from inside the fleet I created with the method:

 public static void createFleet(){
 System.out.println("");
 System.out.println("Please enter the name of the fleet.");
 inputText = scan.nextLine();
 
 fleetCollection.add(new Fleet(inputText));
 printFleets();
 System.out.println("");
 System.out.println("--- Fleet: " + inputText + " added ---");
 System.out.println("");
 
}

So I guess really, my question is: How do I correctly add a new Truck into the list of Trucks, which is inside the Fleet I just made using createFleet(), which is housed in it's own collection of fleets?

Update: Thanks :) you guys really helped me! once again!

deleted 2492 characters in body
Source Link
user1176922
  • 93
  • 1
  • 3
  • 12

In FleetTUI.java I have a list of Fleets (Each fleet will hold its own list of Trucks).

private static ArrayList<Fleet> fleetCollection;

In Fleet.java, I have a list of Truck objects.

ArrayList<Truck> fleetList;

which gets initialized in it's constructor.

 public Fleet(String businessName){
 this.businessName = businessName;
 this.fleetList = new ArrayList<Truck>();
}

So every time I make a new fleet, I am also making a list of Trucks along with it.

In FleetTUI.java, I have a method that adds a truck to a Fleet, made prior:

 public static void addTruck(){
 printFleets();
 System.out.println("Please enter the fleet number where this truck will be added:");
 inputText = scan.nextLine();
 int inputFleetId = Integer.parseInt(inputText);
 System.out.println("Please enter the truck's horn sound:");
 inputText = scan.nextLine();
 String inputHorn = inputText;
 System.out.println("Please enter the truck's fuel capactity:");
 inputText = scan.nextLine();
 int inputFuelCapacity = Integer.parseInt(inputText);
 System.out.println("Please enter the amount of gas remaining in the tank:");
 double inputGasRemaining = Double.parseDouble(scan.nextLine());
 **Fleet.fleetList**.add(inputFleetId, new Truck(inputHorn, inputFuelCapacity, inputGasRemaining));
 System.out.println("--- A truck that goes " + inputHorn + " with " + inputGasRemaining + " gallon(s) in a " + inputFuelCapacity + " gallon tank has been added to " + **fleetCollection.getBusinessName()** + "'s fleet ---" );
 System.out.println("");
}

I have bolded where I am getting errors. The errors are:

Cannot make a static reference to the non-static field Fleet.fleetList

Cannot make a static reference to the non-static method getBusinessName() from the type Fleet

I don't know any other way to access the list of trucks from inside the fleet I created with the method:

 public static void createFleet(){
 System.out.println("");
 System.out.println("Please enter the name of the fleet.");
 inputText = scan.nextLine();
 
 fleetCollection.add(new Fleet(inputText));
 printFleets();
 System.out.println("");
 System.out.println("--- Fleet: " + inputText + " added ---");
 System.out.println("");
 
}

So I guess really, my question is: How do I correctly add a new Truck into the list of Trucks, which is inside the Fleet I just made using createFleet(), which is housed in it's own collection of fleets?

Update: Thanks :) you guys really helped me! once again!

In FleetTUI.java I have a list of Fleets (Each fleet will hold its own list of Trucks).

private static ArrayList<Fleet> fleetCollection;

In Fleet.java, I have a list of Truck objects.

ArrayList<Truck> fleetList;

which gets initialized in it's constructor.

 public Fleet(String businessName){
 this.businessName = businessName;
 this.fleetList = new ArrayList<Truck>();
}

So every time I make a new fleet, I am also making a list of Trucks along with it.

In FleetTUI.java, I have a method that adds a truck to a Fleet, made prior:

 public static void addTruck(){
 printFleets();
 System.out.println("Please enter the fleet number where this truck will be added:");
 inputText = scan.nextLine();
 int inputFleetId = Integer.parseInt(inputText);
 System.out.println("Please enter the truck's horn sound:");
 inputText = scan.nextLine();
 String inputHorn = inputText;
 System.out.println("Please enter the truck's fuel capactity:");
 inputText = scan.nextLine();
 int inputFuelCapacity = Integer.parseInt(inputText);
 System.out.println("Please enter the amount of gas remaining in the tank:");
 double inputGasRemaining = Double.parseDouble(scan.nextLine());
 **Fleet.fleetList**.add(inputFleetId, new Truck(inputHorn, inputFuelCapacity, inputGasRemaining));
 System.out.println("--- A truck that goes " + inputHorn + " with " + inputGasRemaining + " gallon(s) in a " + inputFuelCapacity + " gallon tank has been added to " + **fleetCollection.getBusinessName()** + "'s fleet ---" );
 System.out.println("");
}

I have bolded where I am getting errors. The errors are:

Cannot make a static reference to the non-static field Fleet.fleetList

Cannot make a static reference to the non-static method getBusinessName() from the type Fleet

I don't know any other way to access the list of trucks from inside the fleet I created with the method:

 public static void createFleet(){
 System.out.println("");
 System.out.println("Please enter the name of the fleet.");
 inputText = scan.nextLine();
 
 fleetCollection.add(new Fleet(inputText));
 printFleets();
 System.out.println("");
 System.out.println("--- Fleet: " + inputText + " added ---");
 System.out.println("");
 
}

So I guess really, my question is: How do I correctly add a new Truck into the list of Trucks, which is inside the Fleet I just made using createFleet(), which is housed in it's own collection of fleets?

Update: Thanks :) you guys really helped me! once again!

Update: Thanks :) you guys really helped me! once again!

Rolled back because OP deleted the entire question in order to say thanks, so answers won't make sense
Source Link
DNA
  • 42.7k
  • 12
  • 114
  • 153
Loading
Rollback to Revision 2
Source Link
DNA
  • 42.7k
  • 12
  • 114
  • 153
Loading
deleted 2448 characters in body
Source Link
user1176922
  • 93
  • 1
  • 3
  • 12
Loading
added 208 characters in body
Source Link
user1176922
  • 93
  • 1
  • 3
  • 12
Loading
Source Link
user1176922
  • 93
  • 1
  • 3
  • 12
Loading
lang-java

AltStyle によって変換されたページ (->オリジナル) /