I'm trying to get a string from the content of an object with a custom method in my Android application. The object is an instance of the class Game
and is contained in an arraylist
:
public class Game {
private static List<Game> games = new ArrayList<Game>();
private String teamName1;
private String teamName2;
private int goalsP1;
private int goalsP2;
private String result;
public Game(String teamName1, String teamName2, int goalsP1, int goalsP2)
{
this.teamName1 = teamName1;
this.teamName2 = teamName2;
this.goalsP1 = goalsP1;
this.goalsP2 = goalsP2;
}
public static List getGames() {
return games;
}
public static void addGameToArray(Game randGame) { games.add(randGame);}
public static String getStringFromGame(Game randGame) {
randGame.result = randGame.result + randGame.teamName1 + randGame.goalsP1 + randGame.goalsP2 + randGame.teamName2;
return randGame.result;
}
In my MainActivity
I'm trying to call the getStringFromGame
:
Game game1 = new Game("Man City ","Real Madrid", 5 ,0);
Game.addGameToArray(game1);
String result = Game.getStringFromGame(Game.getGames().get(0));
I get an error:
getStringFromGame cannot be applied to java.lang.Object
What is going wrong?