944,147 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Marked Solved
  • Views: 4755
  • Java RSS
You are currently viewing page 1 of this multi-page discussion thread
Aug 11th, 2006
0

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

Expand Post »
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:

Java Syntax (Toggle Plain Text)
  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.
Reputation Points: 11
Solved Threads: 0
Light Poster
mrsteve is offline Offline
25 posts
since Aug 2006
Aug 11th, 2006
0

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

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.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Aug 11th, 2006
0

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

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.
Reputation Points: 11
Solved Threads: 0
Light Poster
mrsteve is offline Offline
25 posts
since Aug 2006
Aug 11th, 2006
0

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

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?
Reputation Points: 11
Solved Threads: 8
Posting Whiz in Training
hooknc is offline Offline
216 posts
since Aug 2005
Aug 11th, 2006
0

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

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

Java Syntax (Toggle Plain Text)
  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.
Reputation Points: 11
Solved Threads: 0
Light Poster
mrsteve is offline Offline
25 posts
since Aug 2006
Aug 11th, 2006
1

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

In the Storefront class are you importing the package that Item is in?
Reputation Points: 11
Solved Threads: 8
Posting Whiz in Training
hooknc is offline Offline
216 posts
since Aug 2005
Aug 11th, 2006
0

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

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

Java Syntax (Toggle Plain Text)
  1. import org.warren.ecommerce.*;
  2. import org.warren.ecommerce.Item.java;

Is that the correct way to import packages and specific classes?
Reputation Points: 11
Solved Threads: 0
Light Poster
mrsteve is offline Offline
25 posts
since Aug 2006
Aug 11th, 2006
0

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

No.

Try: import com.warren.ecommerce.Item;

If that doesn't work we will have to try something else.
Reputation Points: 11
Solved Threads: 8
Posting Whiz in Training
hooknc is offline Offline
216 posts
since Aug 2005
Aug 11th, 2006
0

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

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:

Java Syntax (Toggle Plain Text)
  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...

Java Syntax (Toggle Plain Text)
  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.
Reputation Points: 11
Solved Threads: 0
Light Poster
mrsteve is offline Offline
25 posts
since Aug 2006
Aug 11th, 2006
0

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

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>();
Reputation Points: 92
Solved Threads: 51
Practically a Posting Shark
Phaelax is offline Offline
856 posts
since Mar 2004

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: parse a csv file (PLEASE HELP)
Next Thread in Java Forum Timeline: copy files from network to local drive





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC