common problem, but still can't solve...

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Dec 2008
Posts: 12
Reputation: Stonehambey is an unknown quantity at this point 
Solved Threads: 0
Stonehambey Stonehambey is offline Offline
Newbie Poster

common problem, but still can't solve...

 
0
  #1
Dec 28th, 2008
As far as I've been able to discern. The "cannot find symbol" compile error is a result of one of 2 mistakes.

1) The class name is spelled incorrectly
2) The class isn't in the same directory as the class trying to instantiate the object or the class isn't in the CLASSPATH variable.

I have a class called Item(already compiled in it's .class file), and it's in the same directory as Storefront.java. Storefront.java instantiates a new Item object, yet when I try to compile Storefront I get a "cannot find symbol error". Here's my bash commands to help illustrate the problem.

  1. dan@dan-laptop:~/java/com/stonehambey/ecommerce$ ls
  2. Item.class Item.java Storefront.java
  3. dan@dan-laptop:~/java/com/stonehambey/ecommerce$ javac Storefront.java
  4. Storefront.java:11: cannot find symbol
  5. symbol : class Item
  6. location: class com.stonehambey.ecommerce.Storefront
  7. Item it = new Item(id, name, price, quant);
  8. ^
  9. Storefront.java:11: cannot find symbol
  10. symbol : class Item
  11. location: class com.stonehambey.ecommerce.Storefront
  12. Item it = new Item(id, name, price, quant);
  13. ^
  14. 2 errors
  15. dan@dan-laptop:~/java/com/stonehambey/ecommerce$

Obviously I'm missing something about how packages and classpaths work, but I don't know what. Any help would be much appreciated.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,217
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 489
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: common problem, but still can't solve...

 
0
  #2
Dec 28th, 2008
Do you have "package" declaration of your Item class?
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 12
Reputation: Stonehambey is an unknown quantity at this point 
Solved Threads: 0
Stonehambey Stonehambey is offline Offline
Newbie Poster

Re: common problem, but still can't solve...

 
0
  #3
Dec 28th, 2008
The Item class is in package com.stonehambey.ecommerce
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,217
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 489
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: common problem, but still can't solve...

 
0
  #4
Dec 28th, 2008
Not the location of the file, but does the class Item starts with
  1. package com.stonehambey.ecommerce
???
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 12
Reputation: Stonehambey is an unknown quantity at this point 
Solved Threads: 0
Stonehambey Stonehambey is offline Offline
Newbie Poster

Re: common problem, but still can't solve...

 
0
  #5
Dec 28th, 2008
Sorry, yes it does
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,217
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 489
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: common problem, but still can't solve...

 
0
  #6
Dec 28th, 2008
Ohh, little slower today.
In your class Item, did you declare constructor that will initialize this class variable with 4 provided values? Something like this?
  1. public Item(int id, String name, double price, int quant){
  2. itemID = id;
  3. itemName = name;
  4. itemPrice = price;
  5. itemQuant = quant;
  6. }
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 12
Reputation: Stonehambey is an unknown quantity at this point 
Solved Threads: 0
Stonehambey Stonehambey is offline Offline
Newbie Poster

Re: common problem, but still can't solve...

 
0
  #7
Dec 28th, 2008
I've pasted the file, it might be easier

http://paste.ubuntu.com/94519/
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,217
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 489
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: common problem, but still can't solve...

 
0
  #8
Dec 28th, 2008
I see nothing wrong with it. Do you mind to post Storefront.java?
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 12
Reputation: Stonehambey is an unknown quantity at this point 
Solved Threads: 0
Stonehambey Stonehambey is offline Offline
Newbie Poster

Re: common problem, but still can't solve...

 
0
  #9
Dec 28th, 2008
sure

http://paste.ubuntu.com/94527/

Although here is something interesting. While I've been posting I've been messing with the files in eclipse. Now eclipse builds as I go and when I navigated to the directory I see a Storefront.class sitting there. Eclipse must've managed to build it somehow. However the JDK javac is still reporting the same error. Strange (although I'm pretty new to Java so maybe I'm missing something...)
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,217
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 489
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: common problem, but still can't solve...

 
0
  #10
Dec 28th, 2008
That explain a lot. If you use command line to compile it you need to do it as follows
  1. javac com/stonehambey/ecommerce/Storefront.java
where both files have to be in respectable locations and you need to run javac from the directory that is parent to your "com" so in your case judging by pasted console output in java directory
  1. dan@dan-laptop:~/java$ javac /com/stonehambey/ecommerce/Storefront.java
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC