• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Java error: 56

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone,

I'm getting an error that reads 56: error: cannot find symbol on line findWholeInventory(cameras[3]); symbol: method findWholeInventory(Camera) location: class Inventory

I'm confused by this because I define this method in the class Camera:


and I have defined Camera in the Inventory class:


DigitalCamera is a subclass that extends Camera, could that be a problem? Everything compiles fine except the inventory class with the aforementioned error. Do I just need to change the syntax on the array that it reads from?
 
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you please post the code of the Inventory class where you are making a call to findWholeInventory. It would be better to post the code of all the 3 classes if its possible.
 
Daniel Kavanaugh
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That would certainly help. There's a lot of unneeded code in DigitalCamera, but I don't like changing things until I get everything working.




 
lowercase baba
Posts: 13091
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
also, if you'd post the complete error message

edit:
so i pulled your code and compiled it, and got this:

C:\slop>javac Inventory.java
Inventory.java:60: cannot find symbol
symbol : method findWholeInventory(Camera)
location: class Inventory
findWholeInventory(cameras[3]);
^
1 error


This tells you that on line 60, the compiler couldn't resolve the method - it has NO idea where to find the definition of this method.

You defined in in the Camera class, so you have to tell it to look there:

Camera.findWholeInventory(cameras[3]);

However, that will give you a new error. See if you can figure out the problem with that...
 
Daniel Kavanaugh
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Inventory.java:56: error: cannot find symbol
findWholeInventory(cameras[3]);
^
symbol: method findWholeInventory(Camera)
location: class Inventory
 
Praveen Kumar M K
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Daniel, referring to line 60 of your Inventory class(the call to findWholeInventory). From Inventory class's perspective, does it know anything about findWholeInventory? Is there way for it to call that method which is actually in Camera class?
 
fred rosenberger
lowercase baba
Posts: 13091
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
also, note that this:

can be simplified to this;

 
Daniel Kavanaugh
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So Should it read cameras.findWholeInventory(cameras[3]); ?

 
Daniel Kavanaugh
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, would it be possible for me to display all the elements in these arrays within a GUI?
 
Praveen Kumar M K
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Daniel Kavanaugh wrote:So Should it read cameras.findWholeInventory(cameras[3]); ?



No it shouldnt. Have a look at how Fred has called it. Are you aware of static methods and variables?
 
fred rosenberger
lowercase baba
Posts: 13091
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Daniel Kavanaugh wrote:Also, would it be possible for me to display all the elements in these arrays within a GUI?


of course it would...but GUI code should be completely separate from the other code. You should get it to work from the command line first, and only then worry about the GUI.
 
fred rosenberger
lowercase baba
Posts: 13091
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Daniel Kavanaugh wrote:So Should it read cameras.findWholeInventory(cameras[3]); ?


Camera is the name of a class.

cameras is the name you gave to a reference variable that points to an array that can hold Camera objects.

Therefore...

Camera is not the same thing as cameras.

 
Marshal
Posts: 80140
418
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Daniel Kavanaugh wrote: . . .

DigitalCamera is a subclass that extends Camera, could that be a problem? . . .

No. Plain and simple: if you haven’t made some dreadful error in how you extended the Camera class, then that will not cause any problems. Fred R has already given you a heavy hint as to what the problem you noticed is.


What Fred didn’t know, because he was writing the reply before you posted all your code, is that you have in fact made a dreadful error in subclassing the Camera class. An error which has to be corrected with generous use of three keys which will really have you cursing me. Ctrl-A delete.

Well, not quite. You have not actually subclassed the Camera class. You have written a new class which says it subclasses it, but you have added all sorts of new information. You have two names, two prices, etc., in the Digitalcamera class. One inherited from Camera, and the other hidden. Look at our FAQ; hiding applies to fields just as it does to methods.
Remove any constructors which don’t do what you want. You want to record make, pixels, price, for every camera. so make sure to get rid of constructors which don’t take all those data. You will probably only want one constructor. Get rid of all the others. Be ruthless. If you want your code to work, you want make pixels price recorded in every Camera object, so make d*mn sure all constructor calls give you that info. And you do that by making sure that is the only constructor tanybody can find.
By the way: are you recording how many Cameras there are in the Camera class? I don’t think that is really part of the Camera class. I think it is part of something else, maybe an Inventory class.
 
Campbell Ritchie
Marshal
Posts: 80140
418
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Daniel Kavanaugh wrote:Also, would it be possible for me to display all the elements in these arrays within a GUI?

Until you have got the Camera and DigitalCamera classes working at the command line, you forget there even is such a thing as a GUI.
 
Campbell Ritchie
Marshal
Posts: 80140
418
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Part 2
Remove every field from the DigitalCamera class which is repeated from the Camera class. You use the fields which are in the Camera class. They should have private access in Camera, but you can gain access if necessary via the getXXX methods. You may find the only field declared in the Digital class is pixels.
Remove every setXXX and getXXX method from the Digital class which appears to be repeated from Camera.
Remove every constructor which doesn’t set up all your fields. I suggest you change your constructor to use the this. idiom you had in Camera. It allows you to use better parameter names.

What you haven’t noticed yet, is how much smaller your digital class is becoming. One setter/getter pair, one field and one constructor. Your constructor will need to pass lots of information to the Camera class with the super(make, price...); call.

Now all you need to do is simplify that DigitalCamera#toString() method. Find out about super.toString(), which I shall not say any more about at this point.

Now, you have a class with subclasses Camera. And see how much simpler it is.

And I see Fred has already told you not to use a GUI. And have you worked out what the error you noticed was?
 
Campbell Ritchie
Marshal
Posts: 80140
418
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When I said remove constructors which don’t initialise all your fields, that applies to both classes.
 
Daniel Kavanaugh
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for posting, guys. Everything compiles now, but unfortunately, I'm still a little confused about some of the stuff stated in your posts. I really apologize.

I've been attempting to correct this program so that it can be displayed in a gui (although all I need it to do is display the arrays in something that isn't the command prompt). Should I just continue, or are there things I absolutely need to fix before displaying the data? Right now, it displays all necessary data, except the result of the findWholeInventory method.




}

I did not change Camera.




 
fred rosenberger
lowercase baba
Posts: 13091
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my honest opinion...

You should throw all this code away, and start over, the right way.

The first think you do is start without a computer. Pencil, paper, and erasers. You start by writing down what you want your code to do. You think about real properties of things. For example, a camera has a make, a model, and price. A camera doesn't have a department, or an inventoryValue.

A Store might have departments, and departments might have inventories...or the Store might have a inventory...

For what it is worth...I have written tons of code that once I got into it, I realized it wasn't right and ditched it all. Most developers will tell you the same thing.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic