how to call a method from another class in android?

I have to classes in android studio for a game. Crate class and player class. I was wondering how to i call the player class in the crate class. I am trying to do it by Player thePlayer = new Player(getContext()); but this just keeps giving me errors for the get context part.

public class Crate {
public static int acrossCrate;
public int upDownCrate;
Player thePlayer = new Player(getContext());  //<--GIVES ERROR

public Crate(Context context) {

    int rect = 1000;
    int height = context.getResources().getDisplayMetrics().heightPixels;
    int width = context.getResources().getDisplayMetrics().widthPixels;

    int startPosX = (width/2)-(rect/2);
    int startPosY = (height/2)-(rect/2);

    acrossCrate = startPosX +300;
    upDownCrate = startPosY +300;


public class Player {
public static int across;
public int upDown;
int boardWidth;
int boardHeight;
int startPosX;
int startPosY;
int stopPosX;
int stopPosY;

public Player(Context context) {

    int rect = 1000;
    boardHeight = context.getResources().getDisplayMetrics().heightPixels;
    boardWidth = context.getResources().getDisplayMetrics().widthPixels;

    startPosX = (boardWidth/2)-(rect/2);
    startPosY = (boardHeight/2)-(rect/2);
    stopPosX = (boardWidth/2)+(rect/2);
    stopPosY = (boardHeight/2)+(rect/2);

    across = startPosX+500;
    upDown = startPosY+500;

Source: android

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.