I'm having a problem with getting values from a map that I save into a Preferences file. I can print out the keys from the map, but not any values. I think it has something to do with the typecasting that I'm doing, but I've tried everything I know of and can't figure it out.
I tested the values from the map that I saved to the preferences file, and they output just fine.
I tried the suggestions below but they did not help
Heres my code
public class SetSettings {
private Actor actor;
private Actor hit;
private Sprite sprite;
private Sprite sprite2;
private Rectangle rect;
private boolean customHit = false;
private ShapeRenderer render = new ShapeRenderer();
public float y;
public float x;
Array<Actor> actors = GameScreen.buttons.stage.getActors();
public SetSettings() {
setOriginal();
setCustom();
rect = new Rectangle();
}
public void setOriginal() {
learnGame.ass.settings.get().clear();
float height = Gdx.graphics.getHeight();
float width = Gdx.graphics.getWidth();
// ui settings
java.util.Map<String, Coords> map = new HashMap<String, Coords>();
map.put("hpBar", new Coords(width - (learnGame.ass.hpBar.getWidth() * 1.02f), height - (height * .076f)));
map.put("hpBase", new Coords(learnGame.ass.hpBar.getX(), learnGame.ass.hpBar.getY()));
for (Entry<String, Coords> key : map.entrySet())
System.out.println(key.getValue().x); // works fine here
}
public void setCustom() {
java.util.Map<String, Coords> amap = (java.util.HashMap<String, Coords>) learnGame.ass.settings.get();
// Float[] nums = amap.get("hpBar");
for (Entry<String, Coords> key : amap.entrySet()) {
// /float t = key.getValue().x; // <-----------error here -- java.lang.String cannot be cast
System.out.println("6" + key.getKey());
// String xz = key.getValue();
}
}
public class Coords {
float x;
float y;
public Coords(float x, float y) {
this.x = x;
this.y = y;
}
}
}