-2

I'm trying to read the something from a context class and always got null. As I debuged it I found out that for some reason there isn't anything written in my context class.

Code where context gets written:

for (Mitarbeiter m : mitarbeiterList){
            if (m.getName().equals(nameSuche)){
               maController = m;
               logger.info(m);
               ContextMAAbrechnung.getInstance().setMitarbeiter(m);
            }
        }

Code of context class:

package slgp.gastrosoftware.gui.controller;

import slgp.gastrosoftware.model.Mitarbeiter;

public class ContextMAAbrechnung {
    private static final ContextMAAbrechnung INSTANCE = new ContextMAAbrechnung();

    private Mitarbeiter mitarbeiter;

    private ContextMAAbrechnung() {}

    public Mitarbeiter getMitarbeiter() {
        return mitarbeiter;
    }

    public void setMitarbeiter(Mitarbeiter mitarbeiter) {
        this.mitarbeiter = mitarbeiter;
    }

    public static ContextMAAbrechnung getInstance() {
        return INSTANCE;
    }
}

When setMitarbeiter is called it is not null: https://snag.gy/JKeFk7.jpg As I get to the this.mitarbeiter = mitarbeiter part one is null and the other isn't. https://snag.gy/BAuFey.jpg

What did I do wrong?

In0cenT
  • 5
  • 2
  • 1
    I'm not quite clear what you're asking at the moment - specifically with "As I get to the this.mitarbeiter = mitarbeiter part one is null and the other isn't" - this is exactly as I'd expect (before executing that statement, the *field* will still be null but the *parameter* won't be.) What do you expect to happen instead? – Michael Berry May 09 '18 at 15:28
  • I'm expecting that mitarbeiter is not null. In my next Controller I'm trying to read from the context class and it returns null. – In0cenT May 09 '18 at 15:35
  • Possible duplicate of [What is a NullPointerException, and how do I fix it?](https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – MMAdams May 09 '18 at 16:01

1 Answers1

-1

There wasn't any mistake there, I didn't check it properly while I was debuging.

In0cenT
  • 5
  • 2