• Post Reply Bookmark Topic Watch Topic
  • New Topic

compiler error: cannot find symbol  RSS feed

 
Heather Dennison
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm taking a Java class. I am in the 4th chapter --- and am stuck.
I am trying to run a program.. and I keep getting a compiler error of AutomobileTest.java:9: cannot find symbol;
I built the automobile class:


and now I am suppose to build a tester which I am not sure how to do... so I took some code from our lab and changed it up a bit to compile and run to get something...


I need help-------
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the ranch

I have added code tags around your source. Please UseCodeTags the next time you want to post some code. It will make it easier to read.
 
Pramod P Deore
Ranch Hand
Posts: 633
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, Heather Dennison Welcome to JavaRanch

You are getting this error because at the time of Object creation of Automobile class you have provided only 2 String at AutomobileTest class as



and


But In class Automobile you had written constructor which takes 3 arguments as



Therefore at the time of object creation compiler gives you error. To remove this error you have to provide 3rd argument double as



and



 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this the exact message you have ? Nothing more ?

I guess it cannot find the Automobile class. If that's true, you'll need to add it to your classpath. In which directory is the Automobile class ? And where is the AutomobileTest class ? Is it in the same directory ?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pramod wrote:You are getting this error because at the time of Object creation of Automobile class you have provided only 2 String at AutomobileTest class

That's why I'm asking if there's nothing more in the error message If the Automobile class is not found, the symbol not found error will say that the class is not found. If the class is found, the symbol not found error will say that the constructor is not found.
 
Heather Dennison
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it is in the same directory. I did some changes and it still is erroring out. here are the changes:
public class AutomobileTest
{
/**
Tests the methods of the Door class
@param args not used
*/
public static void main(String[] args)
{
Automobile frontAutomobile = new Automobile("Front", "open","25");
System.out.println("The front door is " + frontAutomobile.getMake());
System.out.println("Expected: open");
Automobile backAutomobile = new Automobile("Back", "closed","29");
System.out.println("The back door is " + backAutomobile.getModel());
System.out.println("Expected: closed");

Automobile frontAutomobile = new Automobile("Front", "open",1200);


// Use the mutator to change the state variable
backAutomobile.setMake("open");
System.out.println("The back door is " + backAutomobile.getMake());
System.out.println("Expected: open");
// Add code to test the setName mutator here
}
}

And here is the exact error message:
----jGRASP exec: javac -g AutomobileTest.java

AutomobileTest.java:12: cannot find symbol
symbol : constructor Automobile(java.lang.String,java.lang.String,java.lang.String)
location: class Automobile
Automobile frontAutomobile = new Automobile("Front", "open","25");
^
AutomobileTest.java:15: cannot find symbol
symbol : constructor Automobile(java.lang.String,java.lang.String,java.lang.String)
location: class Automobile
Automobile backAutomobile = new Automobile("Back", "closed","29");
^
AutomobileTest.java:19: frontAutomobile is already defined in main(java.lang.String[])
Automobile frontAutomobile = new Automobile("Front", "open",1200);
^
3 errors

----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.
 
Heather Dennison
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
O MY Gosh!! You Guys rock!! I wish I had did this about 10 hours ago You will be hearing from me again soon!! THANKSSSSS!
public class AutomobileTest
{
/**
Tests the methods of the Door class
@param args not used
*/
public static void main(String[] args)
{
Automobile frontAutomobile = new Automobile("Front", "open",1300);
System.out.println("The front door is " + frontAutomobile.getMake());
System.out.println("Expected: open");
Automobile backAutomobile = new Automobile("Back", "closed",1200);
System.out.println("The back door is " + backAutomobile.getModel());
System.out.println("Expected: closed");




// Use the mutator to change the state variable
backAutomobile.setMake("open");
System.out.println("The back door is " + backAutomobile.getMake());
System.out.println("Expected: open");
// Add code to test the setName mutator here
}
}


It runs!! now I have to figure out what I'm suppose to make it do
 
Pramod P Deore
Ranch Hand
Posts: 633
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why you are providing 3rd argument as String instead of double.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I said previously, please UseCodeTags <- click this link.

I think it is in the same directory.

It's not enough to think it is Check it.
If it is, you can tell the compiler to add the current directory to your classpath by using the -cp flag : javac -cp . -g AutomobileTest.java

Your can learn about the classpath in this tutorial.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!