• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Dainius Sablinskas
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • 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?
 
Benjamin Scabbia
Ranch Hand
Posts: 34
Eclipse IDE Python Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
I write in command promt "javac SimpleDotComTester.java"
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • 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
 
K. Tsang
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • 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
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • 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
  • 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
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
It helped, sorri for your time
 
Lokesh Poovaragan
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • 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.
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!