java - Unexplained "is not abstract and does not override abstract method" error -


i can't explain error in game trying make. i'm pretty new game programming, , following tutorial on youtube. far can see doing same in video, still error.

error: uncompilable source code - tilegame.entities.creatures.player not abstract , not override abstract method die() in tilegame.entities.entity @ tilegame.entities.creatures.creature.(creature.java:11)

entity class:

package tilegame.entities;  import java.awt.graphics; import java.awt.rectangle; import tilegame.game; import tilegame.handler;  public abstract class entity {      public static final int default_health = 10;     protected handler handler;     protected float x, y;     protected int width, height;     protected int health;     protected boolean active = true;     protected rectangle bounds;      public entity(handler handler, float x, float y, int width, int height){         this.handler = handler;         this.x = x;         this.y = y;         this.width = width;         this.height = height;         health = default_health;          bounds = new rectangle(0, 0, width, height);     }      public abstract void tick();      public abstract void render(graphics g);      public abstract void die();      public void hurt(int amt){         health += amt;         if(health <= 0){             active = false;             die();         }     }      public boolean checkentitycollisions(float xoffset, float yoffset){         for(entity e : handler.getworld().getentitymanager().getentity()){             if(e.equals(this))                 continue;             if(e.getcollisionbounds(0f, 0f).intersects(getcollisionbounds(xoffset, yoffset)))                 return true;         }         return false;     }      public rectangle getcollisionbounds(float xoffset, float yoffset){         return new rectangle ((int) (x + bounds.x + xoffset), (int) (y + bounds.y + yoffset), bounds.width, bounds.height);     }       public float getx() {         return x;     }      public void setx(float x) {         this.x = x;     }      public float gety() {         return y;     }      public void sety(float y) {         this.y = y;     }      public int getwidth() {         return width;     }      public void setwidth(int width) {         this.width = width;     }      public int getheight() {         return height;     }      public void setheight(int height) {         this.height = height;     }      public int gethealth() {         return health;     }      public void sethealth(int health) {         this.health = health;     }      public boolean isactive() {         return active;     }      public void setactive(boolean active) {         this.active = active;     } } 

player class:

package tilegame.entities.creatures;  import java.awt.color; import java.awt.graphics; import java.awt.image.bufferedimage; import tilegame.game; import tilegame.handler; import tilegame.gfx.animation; import tilegame.gfx.assets;  public class player extends creature{      //animations     private animation animdown, animup, animleft, animright;      public player(handler handler, float x, float y){         super(handler, x, y, creature.default_creature_width, creature.default_creature_height);          bounds.x = 20;         bounds.y = 24;         bounds.width = 23;         bounds.height = 39;          //animations         animdown = new animation(250, assets.player_down);         animup = new animation(250, assets.player_up);         animleft = new animation(250, assets.player_left);         animright = new animation(250, assets.player_right);     }      @override     public void tick() {         //animations         animdown.tick();         animup.tick();         animleft.tick();         animright.tick();          //movement         getinput();         move();         handler.getgamecamera().centeronentity(this);     }      @override     public void die() {         system.out.println("you died");     }      private void getinput(){         xmove = 0;         ymove = 0;          if(handler.getkeymanager().up)             ymove = -speed;         if(handler.getkeymanager().down)             ymove = speed;         if(handler.getkeymanager().left)             xmove = -speed;         if(handler.getkeymanager().right)             xmove = speed;     }      @override     public void render(graphics g) {         g.drawimage(getcurrentanimationframe(), (int) (x - handler.getgamecamera().getxoffset()), (int) (y - handler.getgamecamera().getyoffset()), width, height, null);          //show bounding box          /*g.setcolor(color.red);         g.fillrect((int) (x + bounds.x - handler.getgamecamera().getxoffset()),                  (int) (y + bounds.y - handler.getgamecamera().getyoffset()),                 bounds.width, bounds.height);*/     }      private bufferedimage getcurrentanimationframe(){         if(xmove < 0){             return animleft.getcurrentframe();         }else if(xmove > 0){             return animright.getcurrentframe();         }else if(ymove < 0){             return animup.getcurrentframe();         }else             return animdown.getcurrentframe();     } } 

creature class:

package tilegame.entities.creatures;  import java.awt.graphics; import tilegame.game; import tilegame.handler; import tilegame.entities.entity; import tilegame.tiles.tile;  public abstract class creature extends entity{      public static final float default_speed = 3.0f;     public static final int default_creature_width = 64,                             default_creature_height = 64;      protected float speed;     protected float xmove, ymove;      public creature(handler handler, float x, float y, int width, int height) {         super(handler, x, y, width, height);         speed = default_speed;         xmove = 0;         ymove = 0;     }      public void move(){         if(!checkentitycollisions(xmove, 0f))             movex();         if(!checkentitycollisions(0f, ymove))             movey();       }      public void movex(){         if(xmove > 0){//moving right              int tx = (int) (x + xmove + bounds.x + bounds.width) / tile.tilewidth;              if(!collisionwithtile(tx, (int) (y + bounds.y) / tile.tileheight) && !collisionwithtile(tx, (int) (y + bounds.y + bounds.height) / tile.tileheight)){                 x += xmove;             }else{                 x = tx * tile.tilewidth - bounds.x - bounds.width - 1;             }          }else if(xmove < 0){//moving left             int tx = (int) (x + xmove + bounds.x) / tile.tilewidth;              if(!collisionwithtile(tx, (int) (y + bounds.y) / tile.tileheight) &&                      !collisionwithtile(tx, (int) (y + bounds.y + bounds.height) / tile.tileheight)){                 x += xmove;             }else{                 x = tx * tile.tilewidth + tile.tilewidth - bounds.x;             }         }     }      public void movey(){         if(ymove < 0){//moving             int ty = (int) (y + ymove + bounds.y) / tile.tileheight;              if(!collisionwithtile((int) (x + bounds.x) / tile.tilewidth, ty) &&                     !collisionwithtile((int) (x + bounds.x + bounds.width) / tile.tilewidth, ty)){                 y += ymove;             }else{                 y = ty * tile.tileheight + tile.tileheight - bounds.y;             }          }else if(ymove > 0){ //moving down             int ty = (int) (y + ymove + bounds.y + bounds.height) / tile.tileheight;              if(!collisionwithtile((int) (x + bounds.x) / tile.tilewidth, ty) &&                     !collisionwithtile((int) (x + bounds.x + bounds.width) / tile.tilewidth, ty)){                 y += ymove;             }else{                 y = ty * tile.tileheight - bounds.y - bounds.height - 1;             }         }     }      protected boolean collisionwithtile(int x, int y){         return handler.getworld().gettile(x, y).issolid();     }      // getters , setters     public int gethealth() {         return health;     }      public void sethealth(int health) {         this.health = health;     }      public float getspeed() {         return speed;     }      public void setspeed(float speed) {         this.speed = speed;     }      public float getxmove() {         return xmove;     }      public void setxmove(float xmove) {         this.xmove = xmove;     }      public float getymove() {         return ymove;     }      public void setymove(float ymove) {         this.ymove = ymove;     } } 

i implement same abstract method die(); in stone , tree classes also. cannot understand why error. care explain it? tried re-writing code, restarting netbeans.

your code, minimized (check how create mvce) correct , not throw error:

abstract class entity {     public abstract void die(); }  class player extends creature{      @override     public void die() {         system.out.println("you died");     } }  abstract class creature extends entity{ } 

so check imports, might have player class in other package.


Comments