Getting some errors

Discussion in 'Plugin Development' started by YourTacticalCoder, Jul 11, 2015.

Thread Status:
Not open for further replies.
  1. So basically, I'm trying to make a mini game and some of my lines of code are having some errors. Here are the parts that are getting errors.

    Code:
                GameType.getGame(GameType.getAllGames().get(i).getName()).add(player);
    
    Here is says: The method getName() is undefined for the type Game
    Game is my class name

    Another error I'm getting is

    Code:
    public class GameType {
        private static List<Game> allGames = new ArrayList<Game>();
      
        private static HashMap<String, Game> playerGames = new HashMap<String, Game>();
      
        private String gameName;
      
        public GameType(String gameName) {
            this.gameName = gameName.trim();
            allGames.add(this);
    Here it says: The method add(Game) in the type List<Game> is not applicable for the arguments (GameType)

    Code:
        public void add(Player player) {
            playerGames.put(player.getName(), this);
        }
    Here it's giving me an error on .put();
    it says: The method put(String, Game) in the type HashMap<String,Game> is not applicable for the arguments (String, GameType)

    Please help me with my errors. I hope I gave you enough information to help me with my problem.
     
  2. Offline

    schwabfl

    1) Game does not have a method called "getName"
    2) GameType is not a subclass of Game

    Learn Java
     
  3. Offline

    Totom3

    @YourTacticalCoder You are completely mixing your two classes: Game and GameType. What is the purpose of the GameType class?
     
  4. @Totom3 Yeah I figured it out after a while, never got to say it was solved though since I had no internet.


    @schwabfl I know Java, it was a mistake. Not like you've never made a mistake.
     
  5. Offline

    _Error

    @schwabfl Everyone makes mistakes, If you make a mistake that does not mean you did not learn it.


    @YourTacticalCoder Please mark as solved.
     
  6. @schwabfl I know getName() isn't in my Game class which is why I made it focus on GameType by putting GameType.getGame(GameType.getAllGames().get(i).getName()).add(player);

    My GameType has the getName() method, and GameType is a sub class of Game.

    @schwabfl @Totom3 Also all of my methods from GameType isn't working when I try to implement them into my Game class, can you tell me why?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 12, 2016
  7. Offline

    Totom3

    @YourTacticalCoder We have no idea what you're even trying to do. An explanation of the plugin, as well as the role of each class, their relation between each other and the current code could help us greatly.
     
Thread Status:
Not open for further replies.

Share This Page