I’m initialising a hashmap in a constructor
Menu(float xx, float yy, float ww, float hh){
x = xx;
y = yy;
w = ww;
h = hh;
xoff = 0;
yoff = 0;
toggle =0;
values = new HashMap<String,Boolean>(){{
put("drag",false);
put("resize",false);
put("slide",false);
put("visible",false);
put("border",false);
put("menu",false);
put("menuhover",false);
}};
}
however this returns a null pointer exception when called in an even listener
void event_listener(){
if(drag&&!values.get("drag")){
values.put("drag",true);
}
else if(!drag &&values.get("drag")){
values.put("drag",false);
}
if(resize&&!values.get("resize")){
values.put("resize",true);
}
else if(!resize &&values.get("resize")){
values.put("resize",false);
}
if(slide&&values.get("slide")){
values.put("slide",true);
}
else if(!slide &&values.get("slide")){
values.put("slide",false);
}
if(visible&&!values.get("visible")){
values.put("visible",true);
}
else if(!visible &&values.get("visible")){
values.put("visible",false);
}
if(border && !values.get("border")){
values.put("border",true);
}
else if(!border &&values.get("border")){
values.put("border",false);
}
if(menu && !values.get("menu")){
values.put("menu",true);
}
else if(!menu &&values.get("menu")){
values.put("menu",false);
}
if(menuhover && !values.get("menuhover")){
values.put("menuhover",true);
}
else if(!menuhover &&values.get("menuhover")){
values.put("menuhover",false);
}
};
This only happens in one of my classes, and I dont understand why. Error only happens in the else if part of the code. Not the if part.