| | |
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:
Solved Threads: 0
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.
Obviously I'm missing something about how packages and classpaths work, but I don't know what. Any help would be much appreciated.
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.
Java Syntax (Toggle Plain Text)
dan@dan-laptop:~/java/com/stonehambey/ecommerce$ ls Item.class Item.java Storefront.java dan@dan-laptop:~/java/com/stonehambey/ecommerce$ javac Storefront.java Storefront.java:11: cannot find symbol symbol : class Item location: class com.stonehambey.ecommerce.Storefront Item it = new Item(id, name, price, quant); ^ Storefront.java:11: cannot find symbol symbol : class Item location: class com.stonehambey.ecommerce.Storefront Item it = new Item(id, name, price, quant); ^ 2 errors 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.
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
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Not the location of the file, but does the class Item starts with
???
Java Syntax (Toggle Plain Text)
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
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
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?
In your class Item, did you declare constructor that will initialize this class variable with 4 provided values? Something like this?
Java Syntax (Toggle Plain Text)
public Item(int id, String name, double price, int quant){ itemID = id; itemName = name; itemPrice = price; itemQuant = quant; }
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
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
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
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
•
•
Join Date: Dec 2008
Posts: 12
Reputation:
Solved Threads: 0
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...)
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...)
That explain a lot. If you use command line to compile it you need to do it as follows
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
Java Syntax (Toggle Plain Text)
javac com/stonehambey/ecommerce/Storefront.java
Java Syntax (Toggle Plain Text)
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
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
![]() |
Similar Threads
- Warning: mysql_num_rows() (MySQL)
- Send data on a serial port (C++)
- Common problem solver framework design (C++)
- Windows Xp Freezes/Closes Down (Windows NT / 2000 / XP)
- CPU Usage Problem? (Networking Hardware Configuration)
- Can Anyone Solve This? (Viruses, Spyware and other Nasties)
- IE graphics problem (Web Browsers)
- Need Help for DNS Problem and 'about:blank' Problem ... (Viruses, Spyware and other Nasties)
- internet explorer problem (Web Browsers)
Other Threads in the Java Forum
- Previous Thread: Overwriting the text in the file
- Next Thread: IEEE format to decimal conversion
| Thread Tools | Search this Thread |
911 actionlistener addressbook android api append applet application array arrays automation binary bluetooth character chat class classes client code component consumer csv database desktop draw eclipse error event exception fractal ftp game givemetehcodez graphics gui html ide image input integer j2me japplet java javaarraylist javac javaee javaprojects jmf jni jpanel julia linked linux list loop map method methods mobile netbeans newbie objects online oracle oriented panel print printf problem program programming project projects properties recursion replaydirector reporting researchinmotion robot rotatetext rsa scanner screen se server set size sms sort sql string swing template test threads time tree ubuntu update windows






