not to sound cliche, but...help me please!

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

Join Date: Aug 2006
Posts: 25
Reputation: mrsteve is an unknown quantity at this point 
Solved Threads: 0
mrsteve's Avatar
mrsteve mrsteve is offline Offline
Light Poster

not to sound cliche, but...help me please!

 
0
  #1
Aug 11th, 2006
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:

  1. Storefront.java:14: cannot find symbol
  2. symbol : class Item
  3. location: class org.warren.ecommerce.Storefront
  4. public Item getItem(int i) {
  5. ^
  6. Storefront.java:10: cannot find symbol
  7. symbol : class Item
  8. location: class org.warren.ecommerce.Storefront
  9. Item it = new Item(id, name, price, quant);
  10. ^
  11. Storefront.java:10: cannot find symbol
  12. symbol : class Item
  13. location: class org.warren.ecommerce.Storefront
  14. Item it = new Item(id, name, price, quant);
  15. ^
  16. Storefront.java:15: cannot find symbol
  17. symbol : class Item
  18. location: class org.warren.ecommerce.Storefront
  19. return (Item)catalog.get(i);
  20. ^
  21. Note: Storefront.java uses unchecked or unsafe operations.
  22. 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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 213
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: not to sound cliche, but...help me please!

 
0
  #2
Aug 11th, 2006
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.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 25
Reputation: mrsteve is an unknown quantity at this point 
Solved Threads: 0
mrsteve's Avatar
mrsteve mrsteve is offline Offline
Light Poster

Re: not to sound cliche, but...help me please!

 
0
  #3
Aug 11th, 2006
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.
Last edited by mrsteve; Aug 11th, 2006 at 3:55 pm.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 216
Reputation: hooknc is an unknown quantity at this point 
Solved Threads: 8
hooknc hooknc is offline Offline
Posting Whiz in Training

Re: not to sound cliche, but...help me please!

 
0
  #4
Aug 11th, 2006
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?
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 25
Reputation: mrsteve is an unknown quantity at this point 
Solved Threads: 0
mrsteve's Avatar
mrsteve mrsteve is offline Offline
Light Poster

Re: not to sound cliche, but...help me please!

 
0
  #5
Aug 11th, 2006
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

  1. 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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 216
Reputation: hooknc is an unknown quantity at this point 
Solved Threads: 8
hooknc hooknc is offline Offline
Posting Whiz in Training

Re: not to sound cliche, but...help me please!

 
1
  #6
Aug 11th, 2006
In the Storefront class are you importing the package that Item is in?
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 25
Reputation: mrsteve is an unknown quantity at this point 
Solved Threads: 0
mrsteve's Avatar
mrsteve mrsteve is offline Offline
Light Poster

Re: not to sound cliche, but...help me please!

 
0
  #7
Aug 11th, 2006
Not currently, but I have tried that a few times:

  1. import org.warren.ecommerce.*;
  2. 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
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 216
Reputation: hooknc is an unknown quantity at this point 
Solved Threads: 8
hooknc hooknc is offline Offline
Posting Whiz in Training

Re: not to sound cliche, but...help me please!

 
0
  #8
Aug 11th, 2006
No.

Try: import com.warren.ecommerce.Item;

If that doesn't work we will have to try something else.
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 25
Reputation: mrsteve is an unknown quantity at this point 
Solved Threads: 0
mrsteve's Avatar
mrsteve mrsteve is offline Offline
Light Poster

Re: not to sound cliche, but...help me please!

 
0
  #9
Aug 11th, 2006
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:

  1. import org.warren.ecommerce.*;
  2. 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...

  1. C:\J21work\package\org\warren\ecommerce>javac Storefront.java
  2. Note: Storefront.java uses unchecked or unsafe operations.
  3. Note: Recompile with -Xlint:unchecked for details.
  4.  
  5. C:\J21work\package\org\warren\ecommerce>javac Storefront.java -Xlint:unchecked
  6. Storefront.java:13: warning: [unchecked] unchecked call to add(E) as a member of
  7. the raw type java.util.LinkedList
  8. catalog.add(it);
  9. ^
  10. Storefront.java:25: warning: [unchecked] unchecked conversion
  11. found : java.util.LinkedList
  12. required: java.util.List<T>
  13. Collections.sort(catalog);
  14. ^
  15. Storefront.java:25: warning: [unchecked] unchecked method invocation: <T>sort(ja
  16. va.util.List<T>) in java.util.Collections is applied to (java.util.LinkedList)
  17. Collections.sort(catalog);
  18. ^
  19. 3 warnings
  20.  
  21. 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
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 786
Reputation: Phaelax is on a distinguished road 
Solved Threads: 39
Phaelax Phaelax is offline Offline
Master Poster

Re: not to sound cliche, but...help me please!

 
0
  #10
Aug 11th, 2006
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>();
Reply With Quote Quick reply to this message  
Reply

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



Other Threads in the Java Forum
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC