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:

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.

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.

Is the Item class being compiled? As in are there a Item.java and Item.class files?

What is the package of the Item class?

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

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.

In the Storefront class are you importing the package that Item is in?

commented: v. helpful person, need more of these around who are willing to be so helpful :-D +1

Not currently, but I have tried that a few times:

import org.warren.ecommerce.*;
import org.warren.ecommerce.Item.java;

Is that the correct way to import packages and specific classes?

No.

Try: import com.warren.ecommerce.Item;

If that doesn't work we will have to try something else.

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:

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...

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.

You need to use generics on your collections with 1.5 to avoid this error.

Instead of:
ArrayList myList = new ArrayList();

Use:
ArrayList<MyObject> myList = new ArrayList<MyObject>();

Thank you most kindly for that help! I just now implemented the use of generics and eliminated those two errors. Now there's one last error which I believe I will be able to resolve shortly through trial, error, and researching on a certain website I have found. Thank you for all the help, I will remember you when I rule the world!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.