I can't figure out why it is saying (Vehicle.java:174: cannot find symbol) but there is a symbol, what is going on?

import java.util.Scanner;


public class Vehicle{
protected int hp;
protected int mileage;
protected int year;
public String make;
public String model;

Vehicle(){
hp = 0;
mileage = 0;
year = 0;
}

public void Set(int inputhp, int inputmileage, int inputyear){
hp = inputhp;
mileage = inputmileage;
year = inputyear;
}

//public static void Print(int hp, int mileage, int year){
/*
public  void Print(Vehicle carinfo){

System.out.println("Horsepower: " + carinfo.hp + "\n Mileage: " + carinfo.mileage + "\n Year: " + carinfo.year +
"\n Make: " + carinfo.make + "\n Model: " + carinfo.model);
}
*/



public  void Print(){

System.out.println("Horsepower: " + hp + "\n Mileage: " + mileage + "\n Year: " + year +
"\n Make: " + make + "\n Model: " + model);
}

/*public static void CheckYear(int year, Vehicle carinfo, int i, int yearcheck){

int count = 0;
for(i = 0; i < 1; i++){

if(yearcheck = carinfo[i].year){
System.out.println("The year inputed matches a " + carinfo.year + " " + carinfo.make + " " + carinfo.model + " in our database.");
count++;
										}
												}
												if(count = 0){
												System.out.println("There were no matches of that year");
												}
												}

*/


public static void main(String[] args){

Scanner keyboard = new Scanner(System.in);
int inputyear;
int inputmileage;
int inputhp;
String makeinput;
String modelinput;
int capacitypassed;
boolean isable;
int numdoorsinput;
//System.out.println("How many cars would you like to Enter the information for?");


//int input1 = keyboard.next();

Vehicle carinfo = new Vehicle();


System.out.println("Enter the horsepower of the car.");
inputhp = keyboard.nextInt();
//carinfo.hp.Set() = inputhp;
System.out.println("Enter the mileage of the car.");
inputmileage = keyboard.nextInt();
//carinfo.mileage.set = inputmileage;
System.out.println("Enter the year of the car.");
inputyear = keyboard.nextInt();

carinfo.Set(inputhp, inputmileage, inputyear);

//carinfo.year.set = inputyear;


System.out.println("Enter the make of the car.");
makeinput = keyboard.next();
carinfo.make = makeinput;
System.out.println("Enter the model of the car.") ;
modelinput = keyboard.next();
carinfo.model = modelinput;
carinfo.Print();


Truck[] truckinfo = new Truck[2];
for(int i = 0; i < truckinfo.length; i++){ 
truckinfo[i] = new Truck();
System.out.println("Enter the horsepower of truck number " + (i + 1));
inputhp = keyboard.nextInt();

System.out.println("Enter the mileage of truck number " + (i + 1));
inputmileage = keyboard.nextInt();

System.out.println("Enter the year of truck number " + (i + 1));
inputyear = keyboard.nextInt();

truckinfo[i].Set(inputhp, inputmileage, inputyear);

System.out.println("Enter the make of truck number " + (i + 1));
truckinfo[i].make = makeinput;
System.out.println("Enter the model of truck number " + (i + 1));
truckinfo[i].model = modelinput;
System.out.println("Enter the number of doors for truck number " + (i + 1));
numdoorsinput = keyboard.nextInt();
System.out.println("Enter the towing capacity of truck number " + (i + 1));
capacitypassed = keyboard.nextInt();
truckinfo[i].TruckSet(numdoorsinput, capacitypassed, truckinfo);

}
for(int i = 0; i < truckinfo.length; i++){
truckinfo[i].Print2(i);
}

System.out.println("How much weight are you trying to tow?");
capacitypassed = keyboard.nextInt();

for(int i = 0; i < truckinfo.length; i++){
isable = truckinfo[i].tow_check(capacitypassed, i);
if(isable = true){
System.out.println("We have a truck that can tow the desired weight");
}else System.out.println("We don't have a truck that can tow that much weight.");
}

}






}
class Truck extends Vehicle{
private int numdoors;
private int towingcap;


Truck(){
numdoors = 0;
towingcap = 0;												
}



public void TruckSet(int numdoorsinput, int capacitypassed, Truck[] truckinfo){
towingcap = capacitypassed;
numdoors = numdoorsinput;
}
public void Print2(int i){


System.out.println("Horsepower: " +hp + "\n Mileage: " + mileage + "\n Year: " +year +
"\n Make: " + make + "\n Model: " + model + "\n Number of doors: " + numdoors + 
"\n Towing Capacity: " + towingcap);

}

public boolean tow_check(int capacitypassed, int i){

if(capacitypassed > truckinfo[i].towingcap){
return false;
}else 
return true;
}


}

It would help a lot if you either used [code=java], which would place line numbers in the listing or highlighted the line number in your code, since most can't just quickly pick out line 174. Here is that code with line numbers:

I can't figure out why it is saying (Vehicle.java:174: cannot find symbol) but there is a symbol, what is going on?

import java.util.Scanner;


public class Vehicle{
protected int hp;
protected int mileage;
protected int year;
public String make;
public String model;

Vehicle(){
hp = 0;
mileage = 0;
year = 0;
}

public void Set(int inputhp, int inputmileage, int inputyear){
hp = inputhp;
mileage = inputmileage;
year = inputyear;
}

//public static void Print(int hp, int mileage, int year){
/*
public  void Print(Vehicle carinfo){

System.out.println("Horsepower: " + carinfo.hp + "\n Mileage: " + carinfo.mileage + "\n Year: " + carinfo.year +
"\n Make: " + carinfo.make + "\n Model: " + carinfo.model);
}
*/



public  void Print(){

System.out.println("Horsepower: " + hp + "\n Mileage: " + mileage + "\n Year: " + year +
"\n Make: " + make + "\n Model: " + model);
}

/*public static void CheckYear(int year, Vehicle carinfo, int i, int yearcheck){

int count = 0;
for(i = 0; i < 1; i++){

if(yearcheck = carinfo[i].year){
System.out.println("The year inputed matches a " + carinfo.year + " " + carinfo.make + " " + carinfo.model + " in our database.");
count++;
										}
												}
												if(count = 0){
												System.out.println("There were no matches of that year");
												}
												}

*/


public static void main(String[] args){

Scanner keyboard = new Scanner(System.in);
int inputyear;
int inputmileage;
int inputhp;
String makeinput;
String modelinput;
int capacitypassed;
boolean isable;
int numdoorsinput;
//System.out.println("How many cars would you like to Enter the information for?");


//int input1 = keyboard.next();

Vehicle carinfo = new Vehicle();


System.out.println("Enter the horsepower of the car.");
inputhp = keyboard.nextInt();
//carinfo.hp.Set() = inputhp;
System.out.println("Enter the mileage of the car.");
inputmileage = keyboard.nextInt();
//carinfo.mileage.set = inputmileage;
System.out.println("Enter the year of the car.");
inputyear = keyboard.nextInt();

carinfo.Set(inputhp, inputmileage, inputyear);

//carinfo.year.set = inputyear;


System.out.println("Enter the make of the car.");
makeinput = keyboard.next();
carinfo.make = makeinput;
System.out.println("Enter the model of the car.") ;
modelinput = keyboard.next();
carinfo.model = modelinput;
carinfo.Print();


Truck[] truckinfo = new Truck[2];
for(int i = 0; i < truckinfo.length; i++){ 
truckinfo[i] = new Truck();
System.out.println("Enter the horsepower of truck number " + (i + 1));
inputhp = keyboard.nextInt();

System.out.println("Enter the mileage of truck number " + (i + 1));
inputmileage = keyboard.nextInt();

System.out.println("Enter the year of truck number " + (i + 1));
inputyear = keyboard.nextInt();

truckinfo[i].Set(inputhp, inputmileage, inputyear);

System.out.println("Enter the make of truck number " + (i + 1));
truckinfo[i].make = makeinput;
System.out.println("Enter the model of truck number " + (i + 1));
truckinfo[i].model = modelinput;
System.out.println("Enter the number of doors for truck number " + (i + 1));
numdoorsinput = keyboard.nextInt();
System.out.println("Enter the towing capacity of truck number " + (i + 1));
capacitypassed = keyboard.nextInt();
truckinfo[i].TruckSet(numdoorsinput, capacitypassed, truckinfo);

}
for(int i = 0; i < truckinfo.length; i++){
truckinfo[i].Print2(i);
}

System.out.println("How much weight are you trying to tow?");
capacitypassed = keyboard.nextInt();

for(int i = 0; i < truckinfo.length; i++){
isable = truckinfo[i].tow_check(capacitypassed, i);
if(isable = true){
System.out.println("We have a truck that can tow the desired weight");
}else System.out.println("We don't have a truck that can tow that much weight.");
}

}






}
class Truck extends Vehicle{
private int numdoors;
private int towingcap;


Truck(){
numdoors = 0;
towingcap = 0;												
}



public void TruckSet(int numdoorsinput, int capacitypassed, Truck[] truckinfo){
towingcap = capacitypassed;
numdoors = numdoorsinput;
}
public void Print2(int i){


System.out.println("Horsepower: " +hp + "\n Mileage: " + mileage + "\n Year: " +year +
"\n Make: " + make + "\n Model: " + model + "\n Number of doors: " + numdoors + 
"\n Towing Capacity: " + towingcap);

}

public boolean tow_check(int capacitypassed, int i){

if(capacitypassed > truckinfo[i].towingcap){
return false;
}else 
return true;
}


}

Which points to this line

if(capacitypassed > truckinfo[i].towingcap){

The rest of the compiler message should have told you which symbol was not found - which in this case is "truckinfo" because there is no "truckinfo" in that method or in the class.

ok, i fixed that, and it compiles but after i enter in a few things, it says, Exception in thread "main" java.lang.NullPointerException at Vehicle.main(Vehicle.java:112) but it worked for the vehicle class, but not the truck class, just compile and you'll see what I'm taking about.

import java.util.Scanner;


    public class Vehicle{
      protected int hp;
      protected int mileage;
      protected int year;
      public String make;
      public String model;
   
       Vehicle(){
         hp = 0;
         mileage = 0;
         year = 0;
      }
   
       public void Set(int inputhp, int inputmileage, int inputyear){
         hp = inputhp;
         mileage = inputmileage;
         year = inputyear;
      }
   
   //public static void Print(int hp, int mileage, int year){
   /*
   public  void Print(Vehicle carinfo){
   
   System.out.println("Horsepower: " + carinfo.hp + "\n Mileage: " + carinfo.mileage + "\n Year: " + carinfo.year +
   "\n Make: " + carinfo.make + "\n Model: " + carinfo.model);
   }
   */
   
   
   
       public  void Print(){
      
         System.out.println("Horsepower: " + hp + "\n Mileage: " + mileage + "\n Year: " + year +
            "\n Make: " + make + "\n Model: " + model);
      }
   
   /*public static void CheckYear(int year, Vehicle carinfo, int i, int yearcheck){
   
   int count = 0;
   for(i = 0; i < 1; i++){
   
   if(yearcheck = carinfo[i].year){
   System.out.println("The year inputed matches a " + carinfo.year + " " + carinfo.make + " " + carinfo.model + " in our database.");
   count++;
   									}
   											}
   											if(count = 0){
   											System.out.println("There were no matches of that year");
   											}
   											}
   
   */
   
   
       public static void main(String[] args )throws Exception {
      
         Scanner keyboard = new Scanner(System.in);
         int inputyear;
         int inputmileage;
         int inputhp;
         String makeinput;
         String modelinput;
         int capacitypassed;
         boolean isable;
         int numdoorsinput;
      //System.out.println("How many cars would you like to Enter the information for?");
      
      
      //int input1 = keyboard.next();
      
         Vehicle carinfo = new Vehicle();
      
      
         System.out.println("Enter the horsepower of the car.");
         inputhp = keyboard.nextInt();
      //carinfo.hp.Set() = inputhp;
         System.out.println("Enter the mileage of the car.");
         inputmileage = keyboard.nextInt();
      //carinfo.mileage.set = inputmileage;
         System.out.println("Enter the year of the car.");
         inputyear = keyboard.nextInt();
      
         carinfo.Set(inputhp, inputmileage, inputyear);
      
      //carinfo.year.set = inputyear;
      
      
         System.out.println("Enter the make of the car.");
         makeinput = keyboard.next();
         carinfo.make = makeinput;
         System.out.println("Enter the model of the car.") ;
         modelinput = keyboard.next();
         carinfo.model = modelinput;
         carinfo.Print();
      
      
         Truck[] truckinfo = new Truck[2];
         for(int i = 0; i < truckinfo.length; i++){ 
            //truckinfo[i] = new Truck();
            System.out.println("Enter the horsepower of truck number " + (i + 1));
            inputhp = keyboard.nextInt();
         
            System.out.println("Enter the mileage of truck number " + (i + 1));
            inputmileage = keyboard.nextInt();
         
            System.out.println("Enter the year of truck number " + (i + 1));
            inputyear = keyboard.nextInt();
         
            truckinfo[i].Set(inputhp, inputmileage, inputyear);
         
            System.out.println("Enter the make of truck number " + (i + 1));
            truckinfo[i].make = makeinput;
            System.out.println("Enter the model of truck number " + (i + 1));
            truckinfo[i].model = modelinput;
            System.out.println("Enter the number of doors for truck number " + (i + 1));
            numdoorsinput = keyboard.nextInt();
            System.out.println("Enter the towing capacity of truck number " + (i + 1));
            capacitypassed = keyboard.nextInt();
            truckinfo[i].TruckSet(numdoorsinput, capacitypassed, truckinfo);
         
         }
         for(int i = 0; i < truckinfo.length; i++){
            truckinfo[i].Print2(i);
         }
      
         System.out.println("How much weight are you trying to tow?");
         capacitypassed = keyboard.nextInt();
      
      /*for(int i = 0; i < truckinfo.length; i++){
      isable = truckinfo[i].tow_check(capacitypassed, i);
      if(isable = true){
      System.out.println("We have a truck that can tow the desired weight");
      }else System.out.println("We don't have a truck that can tow that much weight.");
      }
      
      }*/
      
      
      
      
      
      
      }
       class Truck extends Vehicle{
         private int numdoors;
         private int towingcap;
      
      
          Truck(){
            numdoors = 0;
            towingcap = 0;												
         }
      
      
      
          public void TruckSet(int numdoorsinput, int capacitypassed, Truck[] truckinfo){
            towingcap = capacitypassed;
            numdoors = numdoorsinput;
         }
          public void Print2(int i){
         
         
            System.out.println("Horsepower: " +hp + "\n Mileage: " + mileage + "\n Year: " +year +
               "\n Make: " + make + "\n Model: " + model + "\n Number of doors: " + numdoors + 
               "\n Towing Capacity: " + towingcap);
         
         }
      
          public boolean tow_check(int capacitypassed, int i,Truck []truckinfo){
         
            if(capacitypassed > truckinfo[i].towingcap){
               return false;
            }
            else 
               return true;
         }
      
      
      }
   }

so lets look at line 112:

truckinfo[i].Set(inputhp, inputmileage, inputyear);

The two references that you dereference in that line are "truckinfo" and "truckinfo". "truckinfo" isn't null because you initialized it to a new array before the loop.

As for "truckinfo", no elements of the array have ever been set to anything in your code. "truckinfo" is an array of references, so all the elements are initialized to null by default.

ok, i uncommented out what I had commented, now I'm getting this error, truckinfo = new Truck(); Vehicle.java:103: non-static variable this cannot be referenced from a static context, i tried looking this up by googleing but no luck, changing the non statics to statics does no good, any way to fix this error?

import java.util.Scanner;


    public class Vehicle{
      protected int hp;
      protected int mileage;
      protected int year;
      public String make;
      public String model;
   
       Vehicle(){
         hp = 0;
         mileage = 0;
         year = 0;
      }
   
       public void Set(int inputhp, int inputmileage, int inputyear){
         hp = inputhp;
         mileage = inputmileage;
         year = inputyear;
      }
   
   //public static void Print(int hp, int mileage, int year){
   /*
   public  void Print(Vehicle carinfo){
   
   System.out.println("Horsepower: " + carinfo.hp + "\n Mileage: " + carinfo.mileage + "\n Year: " + carinfo.year +
   "\n Make: " + carinfo.make + "\n Model: " + carinfo.model);
   }
   */
   
   
   
       public  void Print(){
      
         System.out.println("Horsepower: " + hp + "\n Mileage: " + mileage + "\n Year: " + year +
            "\n Make: " + make + "\n Model: " + model);
      }
   
   /*public static void CheckYear(int year, Vehicle carinfo, int i, int yearcheck){
   
   int count = 0;
   for(i = 0; i < 1; i++){
   
   if(yearcheck = carinfo[i].year){
   System.out.println("The year inputed matches a " + carinfo.year + " " + carinfo.make + " " + carinfo.model + " in our database.");
   count++;
   									}
   											}
   											if(count = 0){
   											System.out.println("There were no matches of that year");
   											}
   											}
   
   */
   
   
       public static void main(String[] args )throws Exception {
      
         Scanner keyboard = new Scanner(System.in);
         int inputyear;
         int inputmileage;
         int inputhp;
         String makeinput;
         String modelinput;
         int capacitypassed;
         boolean isable;
         int numdoorsinput;
      //System.out.println("How many cars would you like to Enter the information for?");
      
      
      //int input1 = keyboard.next();
      
         Vehicle carinfo = new Vehicle();
      
      
         System.out.println("Enter the horsepower of the car.");
         inputhp = keyboard.nextInt();
      //carinfo.hp.Set() = inputhp;
         System.out.println("Enter the mileage of the car.");
         inputmileage = keyboard.nextInt();
      //carinfo.mileage.set = inputmileage;
         System.out.println("Enter the year of the car.");
         inputyear = keyboard.nextInt();
      
         carinfo.Set(inputhp, inputmileage, inputyear);
      
      //carinfo.year.set = inputyear;
      
      
         System.out.println("Enter the make of the car.");
         makeinput = keyboard.next();
         carinfo.make = makeinput;
         System.out.println("Enter the model of the car.") ;
         modelinput = keyboard.next();
         carinfo.model = modelinput;
         carinfo.Print();
      
      
         Truck[] truckinfo = new Truck[2];
			
         for(int i = 0; i < truckinfo.length; i++){ 
           truckinfo[i] = new Truck();
            System.out.println("Enter the horsepower of truck number " + (i + 1));
            inputhp = keyboard.nextInt();
         
            System.out.println("Enter the mileage of truck number " + (i + 1));
            inputmileage = keyboard.nextInt();
         
            System.out.println("Enter the year of truck number " + (i + 1));
            inputyear = keyboard.nextInt();
         
            truckinfo[i].Set(inputhp, inputmileage, inputyear);
         
            System.out.println("Enter the make of truck number " + (i + 1));
            truckinfo[i].make = makeinput;
            System.out.println("Enter the model of truck number " + (i + 1));
            truckinfo[i].model = modelinput;
            System.out.println("Enter the number of doors for truck number " + (i + 1));
            numdoorsinput = keyboard.nextInt();
            System.out.println("Enter the towing capacity of truck number " + (i + 1));
            capacitypassed = keyboard.nextInt();
            truckinfo[i].TruckSet(numdoorsinput, capacitypassed, truckinfo);
         
         }
         for(int i = 0; i < truckinfo.length; i++){
            truckinfo[i].Print2(i);
         }
      
         System.out.println("How much weight are you trying to tow?");
         capacitypassed = keyboard.nextInt();
      
      /*for(int i = 0; i < truckinfo.length; i++){
      isable = truckinfo[i].tow_check(capacitypassed, i);
      if(isable = true){
      System.out.println("We have a truck that can tow the desired weight");
      }else System.out.println("We don't have a truck that can tow that much weight.");
      }
      
      }*/
      
      
      
      
      
      
      }
      class Truck extends Vehicle{
         private int numdoors;
         private int towingcap;
      
      
          Truck(){
            numdoors = 0;
            towingcap = 0;												
         }
      
      
      
          public void TruckSet(int numdoorsinput, int capacitypassed, Truck[] truckinfo){
            towingcap = capacitypassed;
            numdoors = numdoorsinput;
         }
          public void Print2(int i){
         
         
            System.out.println("Horsepower: " +hp + "\n Mileage: " + mileage + "\n Year: " +year +
               "\n Make: " + make + "\n Model: " + model + "\n Number of doors: " + numdoors + 
               "\n Towing Capacity: " + towingcap);
         
         }
      
          public boolean tow_check(int capacitypassed, int i,Truck []truckinfo){
         
            if(capacitypassed > truckinfo[i].towingcap){
               return false;
            }
            else 
               return true;
         }
      
      
      }
   }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.