• Post Reply Bookmark Topic Watch Topic
  • New Topic

Error : Cant find symbol  RSS feed

 
Dhruv Mehra
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm Java newbie and learning essentially from the book Head First Java. I was compiling my first program when a bunch of errors showed up and I dont know how to fix them as I'm religiously following the book.

Code for my first class :-
=============================================================================================================================================

=============================================================================================================================================

Second Class :-


=============================================================================================================================================

The first one compiles easily but when I compile the second one it shows an error

C:\Users\Dhruv>javac JAVA\SinkADotCom\SimpleDotComTester.java
JAVA\SinkADotCom\SimpleDotComTester.java:4: error: cannot find symbol
SimpleDotCom dot = new SimpleDotCom();
^
symbol: class SimpleDotCom
location: class SimpleDotComTester
JAVA\SinkADotCom\SimpleDotComTester.java:4: error: cannot find symbol
SimpleDotCom dot = new SimpleDotCom();
^
symbol: class SimpleDotCom
location: class SimpleDotComTester
2 errors
=============================================================================================================================================

Please HELP I'm a newbie and this is my first program!!!
 
Damian R Smith
Greenhorn
Posts: 5
Android Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its showing an error because your trying to make an object of class A in class B.. So change the object from ShowDotCom to ShowDotComTester instead.. then you use that reference to access the method in the other class.
 
Mike. J. Thompson
Bartender
Posts: 689
17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Damian R Smith wrote:Its showing an error because your trying to make an object of class A in class B.. So change the object from ShowDotCom to ShowDotComTester instead.. then you use that reference to access the method in the other class.


There's nothing wrong declaring and instantiating an object of SimpleDotCom inside SimpleDotComTest. The problem is likely to be because SimpleDotComTest does not import SimpleDotCom.

Dhruv, what package are both of your classes in? Are they in the same package or different packages?
 
Tony Docherty
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

There's nothing wrong with your code (except for the different spelling of setLocatrionCells in the 2 classes).

Your classes don't have package statements so they must both be in the same directory for the classes to be visible to each other.

<Edit> Too slow again
 
Dhruv Mehra
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the response

Both classes are in the same directory. Even after changing the spelling of setLocatrionCells to setLocationCells the compiler gives the same error.

=========================================================================================================================================


C:\Users\Dhruv>javac JAVA\SinkADotCom\SimpleDotCom.java

C:\Users\Dhruv>javac JAVA\SinkADotCom\SimpleDotComTester.java
JAVA\SinkADotCom\SimpleDotComTester.java:4: error: cannot find symbol
SimpleDotCom dot = new SimpleDotCom();
^
symbol: class SimpleDotCom
location: class SimpleDotComTester
JAVA\SinkADotCom\SimpleDotComTester.java:4: error: cannot find symbol
SimpleDotCom dot = new SimpleDotCom();
^
symbol: class SimpleDotCom
location: class SimpleDotComTester
2 errors

=======================================================================================================================================
Thanks again in advance
 
Dhruv Mehra
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I deleted all the class files, restarted the command line prompt and compiled everything again, this time it worked. Thanks guys .
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!