Search code examples
javaimagegraphicsjapplet

Undefined method/Cannot be resolved


I'm in the process of creating a simple game and I stumbled upon an error I can't resolve. When trying to import/draw an image with Graphics an error pops up:

Multiple markers at this line
    - getCenterX cannot be resolved or is not a field
    - getCenterY cannot be resolved or is not a field
    - getCenterY cannot be resolved or is not a field

I'm most certain that I imported everything correctly:

Declarations/Variables/Definitions

// In the class "StartingClass"
private Robot robot;
private URL base;

// In the class "Robot"
private int centerX = 100;
private int centerY = 328;

Methods in the class "StartingClass"

@Override
    public void paint(Graphics g) {
        g.drawImage(character, robot.getCenterX()- 61, robot.getCenterY - 62, this);
    }

@Override
    public void start() {
        robot = new Robot();
    }

Methods in the class "Robot"

public int getCenterX() {
        return centerX;
    }

public int getCenterY() {
        return centerY;
    }

Solution

  • robot.getCenterY
    

    I think the problem is this, as getCenterY is not a variable. Its a typo for the method getCenterY(). To fix, just add the parenthetical at the end. Otherwise, please post more snippets as not much can be determined from your code provided.