I got a problem even my professor couldn't solve after an hour of investigation: I have a map which stores a highscore value for each level, where the levels are saved as strings and the integer represents the highscore. Now, when I try to read the highscore for a level, I get this very weird problem: Upon calling the method to read the highscore, I get an error saying
java.lang.String cannot be cast to java.lang.Integer
The code is the following
public Map<String, Integer> highscores = new HashMap<>();
highscores.put("Level1", 35); //Example, we read it from a file
int highscore = highscores.get("Level1");
The error occurs in the third line. Does anyone have an idea why this happens? Integer.parseInt doesn't work either, as that method says it needs a String instead of an Integer as an argument, meaning the right hand side of the line is in fact an Integer. Any help is greatly appreciated.