| | |
not to sound cliche, but...help me please!
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
Hello everyone, I am new to Java programming as well as to these most excellent forums and I have a problem with some sample code from a book that is teaching me Java. The code is supposed to demonstrate packages, access control, interfaces, and encapsulation. My problem is that when I try to compile one of the files I get the following errors:
The Item class is in a different file in the same folder and part of the same package and is declared public so I'm not sure why the compiler won't recognize it when I try to compile this other file. Any help you guys can offer would be greatly appreciated...oh, and I apologize in advance if this error is covered in a different thread, I couldn't find it if it was.
Java Syntax (Toggle Plain Text)
Storefront.java:14: cannot find symbol symbol : class Item location: class org.warren.ecommerce.Storefront public Item getItem(int i) { ^ Storefront.java:10: cannot find symbol symbol : class Item location: class org.warren.ecommerce.Storefront Item it = new Item(id, name, price, quant); ^ Storefront.java:10: cannot find symbol symbol : class Item location: class org.warren.ecommerce.Storefront Item it = new Item(id, name, price, quant); ^ Storefront.java:15: cannot find symbol symbol : class Item location: class org.warren.ecommerce.Storefront return (Item)catalog.get(i); ^ Note: Storefront.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details.
The Item class is in a different file in the same folder and part of the same package and is declared public so I'm not sure why the compiler won't recognize it when I try to compile this other file. Any help you guys can offer would be greatly appreciated...oh, and I apologize in advance if this error is covered in a different thread, I couldn't find it if it was.
yup, cliche.
Both the question and the (rather obvious) answer have been posted too many times to count and as usual the person asking the question can't be bothered to do his own research towards finding that answer.
Both the question and the (rather obvious) answer have been posted too many times to count and as usual the person asking the question can't be bothered to do his own research towards finding that answer.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
I have done research on the "cannot find symbol" error message and the solutions all involved spellchecking, which I have done extensively (I have even gone as far as writing all the code over a second time more slowly and carefully). The errors are the same both times. It is obvious that I am using a class name in my code that the compiler does not recognize, however, when I try to import the class I get the same messages. I am not certain it needs to be imported anyway, for two reasons: first off, all the classes I have written from this book so far have compiled with no problem so I don't think I should have to add anything to the author's code to make to work; second, the two files are in the same directory...although I actually don't know enough about the programming language to state why that should matter.
Again, I apologize for posting a question that may have already been answered, but I could not find a similar one that would help in any of the other threads on the first or second page--granted, I only checked the ones with subject lines that seemed relevant, but please if someone could just give me some help instead of merely insulting my lack of knowledge regarding what is, according to the guy who first replied, an obvious problem.
Again, I apologize for posting a question that may have already been answered, but I could not find a similar one that would help in any of the other threads on the first or second page--granted, I only checked the ones with subject lines that seemed relevant, but please if someone could just give me some help instead of merely insulting my lack of knowledge regarding what is, according to the guy who first replied, an obvious problem.
Last edited by mrsteve; Aug 11th, 2006 at 3:55 pm.
Yes, the Item class compiled successfully--there is an Item.java and an Item.class. They also happen to be in the same package, with the code
on the first line of each .java file. I have written the code for and placed these files precisely as the author indicated in the text. hmm perhaps I should try placing the folder which this package is contained in, in the classpath environmental variable. I get the feeling it might make it work although I did already try it on my other computer which was returning the same errors when I tried compiling Storefront.java
...ok, that didn't work. Hmm...tricksy little problemses.
Java Syntax (Toggle Plain Text)
package org.warren.ecommerce;
on the first line of each .java file. I have written the code for and placed these files precisely as the author indicated in the text. hmm perhaps I should try placing the folder which this package is contained in, in the classpath environmental variable. I get the feeling it might make it work although I did already try it on my other computer which was returning the same errors when I tried compiling Storefront.java
...ok, that didn't work. Hmm...tricksy little problemses.
Not currently, but I have tried that a few times:
Is that the correct way to import packages and specific classes?
Java Syntax (Toggle Plain Text)
import org.warren.ecommerce.*; import org.warren.ecommerce.Item.java;
Is that the correct way to import packages and specific classes?
Steve Warren,
Student of Engineering,
Nerd Extraordinaire,
Not a Squirrel
Student of Engineering,
Nerd Extraordinaire,
Not a Squirrel
Ok, now we're getting somewhere...last time I tried putting the import statements in the Item.java file which really doesn't make much sense since I'd be trying to import a file to itself...dumb. Anyway, I put this:
into the Storefront.java file and that eliminated the four errors. I used org because org is the name of the folder, not com...
Anyway, that leaves me with the following problem, which I will now try researching on google...
If you have any simple advice to offer on this in case I don't find anything on google, I'd be much obliged :-D.
Java Syntax (Toggle Plain Text)
import org.warren.ecommerce.*; import org.warren.ecommerce.Item;
into the Storefront.java file and that eliminated the four errors. I used org because org is the name of the folder, not com...
Anyway, that leaves me with the following problem, which I will now try researching on google...
Java Syntax (Toggle Plain Text)
C:\J21work\package\org\warren\ecommerce>javac Storefront.java Note: Storefront.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. C:\J21work\package\org\warren\ecommerce>javac Storefront.java -Xlint:unchecked Storefront.java:13: warning: [unchecked] unchecked call to add(E) as a member of the raw type java.util.LinkedList catalog.add(it); ^ Storefront.java:25: warning: [unchecked] unchecked conversion found : java.util.LinkedList required: java.util.List<T> Collections.sort(catalog); ^ Storefront.java:25: 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 C:\J21work\package\org\warren\ecommerce>
If you have any simple advice to offer on this in case I don't find anything on google, I'd be much obliged :-D.
Steve Warren,
Student of Engineering,
Nerd Extraordinaire,
Not a Squirrel
Student of Engineering,
Nerd Extraordinaire,
Not a Squirrel
![]() |
Other Threads in the Java Forum
- Previous Thread: parse a csv file (PLEASE HELP)
- Next Thread: copy files from network to local drive
| Thread Tools | Search this Thread |
Tag cloud for Java
actuate android api apple applet application arguments array arrays automation binary birt block bluetooth c# capture chat class classes client code color compile component count database defaultmethod design draw eclipse error event eventlistener exception expand file fractal game givemetehcodez graphics gui helpwithhomework html ide if_statement image input integer j2me java javaarraylist javaee javaprojects jetbrains jmf jni jpanel jtree julia keyword linux list loop macintosh map method methods mobile netbeans newbie number object oracle os print problem program programming project read recursion replaydirector scanner screen server set size sms socket sort sql string subclass swing test textfield threads time tree windows






