• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

I am beginner and I am haveing a problem with one of First Head Java demo

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, please help me with this childish problem. I have two classes:
First main:



Second:



Second one compiles normaly, but first one promts me a problem:
SimpleDotComTester.java:7: error: cannot find symbol
SimpleDotCom dot = new SimpleDotCom();
^

What is wrong?
 
Ranch Hand
Posts: 34
Eclipse IDE Python Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just tested it in eclipse and it works fine. How are you compiling and running your code?
 
Dainius Sablinskas
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I write in command promt "javac SimpleDotComTester.java"
 
author
Posts: 23928
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Benjamin Scabbia wrote:Just tested it in eclipse and it works fine. How are you compiling and running your code?



Eclipse is not good at hunting down this issue here. It could be caused by the packaging. It could be caused by the location of the source or class files. It could be caused by the classpath. All of these are taken care of for you by Eclipse.

Henry
 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are the 2 classes in the same package (folder)? If not, is there an "import" statement to that package?

By compiling the main (Tester) class, the compiler should able to find the dependent classes and compile those.
 
Henry Wong
author
Posts: 23928
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dainius Sablinskas wrote:I write in command promt "javac SimpleDotComTester.java"




Can you show us your directory layout? Where are the files located? And where are you running this code from?

Can you show us you classpath? Assuming that you set one up?

And are you showing us the full code? Meaning do you have a "package" keyword on the top of your source file?

Henry
 
Dainius Sablinskas
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In code I added "package Java;" because my .java files sits in "C:\Java".
I thought classpath has to be described after you compile and trying to run.
 
Henry Wong
author
Posts: 23928
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dainius Sablinskas wrote:In code I added "package Java;" because my .java files sits in "C:\Java".
I thought classpath has to be described after you compile and trying to run.



No, that is *not* how it works. Remove those lines. And don't set a classpath. You should learn how to do it correctly later in the book.

And BTW, welcome to the ranch...
Henry
 
Dainius Sablinskas
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It helped, sorri for your time
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Explaining by images:



Put both of the files in a single folder, remove all the package definitions, and then compile using javac *.java. In case you didn't know, *.java, where * is a wildcard to select every java file in the current directory and then compiles it.
 
Marshal
Posts: 76415
365
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Did you copy the code by hand from the book or did you download it from the website? Does it include package declarations? Look at the very first line of the file.
 
Any sufficiently advanced technology will be used as a cat toy. And this tiny ad contains a very small cat:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic