aspose file tools*
The moose likes Beginning Java and the fly likes Java error: 56 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java error: 56" Watch "Java error: 56" New topic
Author

Java error: 56

Daniel Kavanaugh
Greenhorn

Joined: Aug 12, 2012
Posts: 11
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?
Praveen Kumar M K
Ranch Hand

Joined: Jul 03, 2011
Posts: 256
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

Joined: Aug 12, 2012
Posts: 11
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.




fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10925
    
  12

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


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Daniel Kavanaugh
Greenhorn

Joined: Aug 12, 2012
Posts: 11
Inventory.java:56: error: cannot find symbol
findWholeInventory(cameras[3]);
^
symbol: method findWholeInventory(Camera)
location: class Inventory
Praveen Kumar M K
Ranch Hand

Joined: Jul 03, 2011
Posts: 256
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
Bartender

Joined: Oct 02, 2003
Posts: 10925
    
  12

also, note that this:

can be simplified to this;

Daniel Kavanaugh
Greenhorn

Joined: Aug 12, 2012
Posts: 11
So Should it read cameras.findWholeInventory(cameras[3]); ?

Daniel Kavanaugh
Greenhorn

Joined: Aug 12, 2012
Posts: 11
Also, would it be possible for me to display all the elements in these arrays within a GUI?
Praveen Kumar M K
Ranch Hand

Joined: Jul 03, 2011
Posts: 256
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
Bartender

Joined: Oct 02, 2003
Posts: 10925
    
  12

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
Bartender

Joined: Oct 02, 2003
Posts: 10925
    
  12

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.

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36579
    
  16
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
Sheriff

Joined: Oct 13, 2005
Posts: 36579
    
  16
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
Sheriff

Joined: Oct 13, 2005
Posts: 36579
    
  16
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
Sheriff

Joined: Oct 13, 2005
Posts: 36579
    
  16
When I said remove constructors which don’t initialise all your fields, that applies to both classes.
Daniel Kavanaugh
Greenhorn

Joined: Aug 12, 2012
Posts: 11
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
Bartender

Joined: Oct 02, 2003
Posts: 10925
    
  12

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java error: 56
 
Similar Threads
Array Sorting
Slowly getting it
Heelllpppp! I'm sooo lost
Counting in Array List/ Standard deviation
Still working on this inventory project, issue with inventory array