# Null pointer exception on hashmap

**URL:** <https://discourse.processing.org/t/null-pointer-exception-on-hashmap/15627>\
**Category:** Coding Questions\
**Created:** [November 18, 2019, 10:52pm UTC](https://discourse.processing.org/t/null-pointer-exception-on-hashmap/15627 "2019-11-18T22:52:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [November 18, 2019, 10:52pm UTC](https://discourse.processing.org/t/null-pointer-exception-on-hashmap/15627/1 "2019-11-18T22:52:10Z")

</div>

I’m initialising a hashmap in a constructor

```auto
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

```auto
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.

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [November 18, 2019, 10:58pm UTC](https://discourse.processing.org/t/null-pointer-exception-on-hashmap/15627/2 "2019-11-18T22:58:39Z")

</div>

Overloaded the constructor and failed to add it to all constructors.
