wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Error can't find class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Error can Watch "Error can New topic
Author

Error can't find class

Di Fusio
Greenhorn

Joined: Apr 15, 2011
Posts: 7
Hi peeps,

I've got the following two classes:


and:


Item.java compiles just fine, but Storefront.java gives me:

C:\JavaWork\org\cadenhead\ecommerce>javac Storefront.java
Storefront.java:15: cannot find symbol
symbol : class Item
location: class org.cadenhead.ecommerce.Storefront
public Item getItem(int i) {
^
Storefront.java:11: cannot find symbol
symbol : class Item
location: class org.cadenhead.ecommerce.Storefront
Item it = new Item(id, name, price, quant);
^
Storefront.java:11: cannot find symbol
symbol : class Item
location: class org.cadenhead.ecommerce.Storefront
Item it = new Item(id, name, price, quant);
^
Storefront.java:16: cannot find symbol
symbol : class Item
location: class org.cadenhead.ecommerce.Storefront
return (Item)catalog.get(i);
^
Note: Storefront.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
4 errors


I can't find the reason for this error.

Any help would be great.

fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11479
    
  16

Do you have a classpath set?


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Di Fusio
Greenhorn

Joined: Apr 15, 2011
Posts: 7
Yeah:

.;C:\Program Files (x86)\Java\jre6\lib\ext\QTJava.zip;C:\Program Files\Java\jdk1.6.0_24\Programs\

Should i add c:\javawork?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19761
    
  20

Add, no. Replace the current value, yes. But not system wide; simply use the -cp flag.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Hauke Ingmar Schmidt
Rancher

Joined: Nov 18, 2008
Posts: 433
    
    2
Di Fusio wrote:


Item.java compiles just fine, but Storefront.java gives me:

[i]C:\JavaWork\org\cadenhead\ecommerce>javac Storefront.java


You are in the wrong directory when calling javac. Compile from c:\JavaWork as current directory.
Di Fusio
Greenhorn

Joined: Apr 15, 2011
Posts: 7
Great, this works guys, but now it gives me:

C:\JavaWork\org\cadenhead\ecommerce>javac Storefront.java
Note: Storefront.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

C:\JavaWork\org\cadenhead\ecommerce>javac -Xlint:unchecked Storefront.java
Storefront.java:12: warning: [unchecked] unchecked call to add(E) as a member of
the raw type java.util.LinkedList
catalog.add(it);
^
Storefront.java:24: warning: [unchecked] unchecked conversion
found : java.util.LinkedList
required: java.util.List<T>
Collections.sort(catalog);
^
Storefront.java:24: warning: [unchecked] unchecked method invocation: <T>sort(ja
va.util.List<T>) in java.util.Collections is applied to (java.util.LinkedList)
Collections.sort(catalog);
^
3 warnings

Is that classpath related as well?
Hauke Ingmar Schmidt
Rancher

Joined: Nov 18, 2008
Posts: 433
    
    2
No, that is because your code is using collections without generic types - which you should add.
 
Don't get me started about those stupid light bulbs.
 
subject: Error can't find class