I have been getting a NullPointerEXception ERROR, Please help me fix this error I have been trying to fix it for the past 2 hours the problem is on line 35, thanks in advance!
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
public class Player extends Actor
{
public boolean isGrounded;
boolean isJumping;
boolean atRightEdge;
boolean atLeftEdge;
int yVel;
int jumpTime;
int jumpTimer;
public int xVel;
public Player()
{
yVel = 0;
jumpTime = 10;
xVel = 4;
}
public void act()
{
move();
jump();
checkGround();
checkEdge();
gravity();
}
public void gravity()
{
WorldMethods world = (WorldMethods) getWorld();
Feet feet = (Feet) world.getFeet();
int gravityForce = -1;
int terminalVel = -20;
if(!isGrounded && !feet.feetGrounded)
{
//doesn't allow the player to go faster than 20 pixels per act cycle
if(yVel > terminalVel){yVel += gravityForce;}
else {yVel = terminalVel;}
}
else if(!isGrounded && feet.feetGrounded && !isJumping)
{
yVel = 0;
jumpTimer = 0;
}
else
{
yVel = 1;
}
setLocation(getX() ,getY() - yVel);
}
public void jump()
{
int jumpForce = 10;
if(Greenfoot.isKeyDown("space") && jumpTimer < jumpTime)
{
yVel = jumpForce;
isJumping = true;
}
if(yVel <= 0)
{
isJumping = false;
}
jumpTimer++;
}
public void move()
{
if(Greenfoot.isKeyDown("a") && !atLeftEdge)
{
setLocation(getX() - xVel, getY());
}
if(Greenfoot.isKeyDown("d") && !atRightEdge)
{
setLocation(getX() + xVel, getY());
}
}
public void checkGround()
{
Ground touchingGround = (Ground) getOneIntersectingObject (Ground.class);
if(touchingGround != null)
{
isGrounded = true;
}
else
{
isGrounded = false;
}
}
public void checkEdge()
{
WorldMethods world = (WorldMethods) getWorld();
if(getX() <= world.playerWidth/2)
{
atLeftEdge = true;
}
else{
atLeftEdge = false;
}
if(getX() >= world.screenWidth - world.playerWidth/2)
{
atRightEdge = true;
}
else
{
atRightEdge = false;
}
}
public void lava()
{
if (isTouching(Lava.class))
setLocation(29, 597);
}
public void bang()
{
if (isTouching(Bullet.class))
setLocation(970, 114);
}
}