Skip to main content
GameDev.net gamedev.net
🔒 Locked

[java] Cannot Find Symbol - Constructor Entity()

Started by Gallivan Feb 20, 2009 at 1:25 PM 2 replies 2.4k views
Original Post
Gallivan
Gallivan
I have the following two classes, one of which extends the other. Entity -> Food (I realize that food does not have anything specific at this point.) I keep receiving the message: Cannot Find Symbol - Constructor Entity()...

import java.awt.*;
import java.awt.image.*;
import java.io.*;
import javax.imageio.*;

public class Entity
{
    int x, y; // coordinates
    int width, height;
    int id;
    BufferedImage image1,image2;
    boolean isSelected = false;
    BufferedImage currentImage;
    
    
    public Entity( int setX, int setY, int setWidth, int setHeight, int entityCount ) {
        x = setX;
        y = setY;
        width = setWidth;
        height = setHeight;
        id = entityCount;
    }
}

import java.awt.*;
import java.awt.image.*;
import java.io.*;
import javax.imageio.*;

public class Food extends Entity
{
    public Food() {
        super();
    }
}
swiftcoder
swiftcoder
Entity has no default (zero-argument) constructor, so you either need to define one, or pass all the required arguments during the call to super().
Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]
Gallivan
Gallivan
Thanks!
Argus2
Argus2
Yep. This might be confusing because in Java, if you don't declare a constructor, then the default no-argument constructor (Entity()) will be added for you behind the scenes, but if you do declare a constructor in Entity (as you have), then no default constructor will be added.

So you either need to create a no-argument constructor in Entity to match the super() call, or alter your call to super to match the existing constructor (super(int, int, int, int, int);).

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.