-2

I have two errors both the same and they follow below:

class FBox {//...}
class FBPlayer
{
    //Initialized instances
    FBox game = new FBox();
    **FBPillar pillar = new FBPillar();**
    **FBObjects objects = new FBObjects();**
    //Lots o Properties...

    public boolean get_Alive() { return this.b_PlayerAlive; }
    public void set_Alive(boolean alive) { this.b_PlayerAlive = alive; }

    //My Error ridden Method
    public void checkCollision()
    {
        if(get_YPos() >= **objects**.get_Ground())
                          ^My Error was incorrect name for my instance
        {
            set_Alive(false);
        }
        else if(get_Bounds().intersects(**pillar**.get_Bounds()))   
                                ^My Error was incorrect name for my instance
        {
            set_Alive(false);
        } 
    }

class FBPillar
{
    public int get_Bounds() {return 'the variable'; }
}

class FBObjects
{
    public int get_Ground() {return 'the variable'; }
}

The error is in the if statement as well as the else if statement When i run it it returns the error:

FBox.java:178: error: non-static method get_Bounds() cannot be referenced from a static context
               else if(get_Bounds().intersects(**FBPillar**.get_Bounds()))

The same error for the if statement but with FBObjects.get_Ground()) ^

Lance Roberts
  • 22,383
  • 32
  • 112
  • 130
Caleb
  • 56
  • 7
  • Do you know what static and non-static methods are? – RealSkeptic Feb 25 '15 at 18:29
  • http://stackoverflow.com/questions/11993077/difference-between-static-methods-and-instance-methods/11993118#11993118 You are referencing a non-static method as though it were a static method. You *must* instantiate an object to access a non-static method on it. – Nathaniel Ford Feb 25 '15 at 18:30
  • Turn your head slightly to the right and scroll down to the _Related_ section. – Sotirios Delimanolis Feb 25 '15 at 18:32

1 Answers1

0

Whose bounds are you talking about? You probably mean

if (get_Bounds().intersects(pillar.get_Bounds())) {
    …
}

I'd also add that

 FBPlayer player = new FBPlayer();

means that a player contains a player, which is probably isn't what you intended.

200_success
  • 7,286
  • 1
  • 43
  • 74