V
V
vladocc2015-12-20 09:43:11
Java
vladocc, 2015-12-20 09:43:11

Why can't add an object to a Map from its constructor in Java?

public class Quest {

    static Map<Integer, Object> IDs;
    String Text;

    Quest(String Text, int ID){
        this.Text = Text;
        IDs.put(ID, this);
    }

The program throws a NullPointerException on the line IDs.put(ID, this);
What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
wol_fi, 2015-12-20
@vladocc

What am I doing wrong?

Declared a variable but didn't give it a value.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question