• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Error : Cant find symbol

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!!!
 
Greenhorn
Posts: 5
Android Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 689
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 .
 
We're all out of roofs. But we still have tiny ads:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic