Java NullPointerException while using array

flixx10 :

Why do I get a NullPointerException, when I try to execute the method "temperaturEingeben"? I hope you can understand my code because it´s in German.

public class Temperaturanzeige{                                 
    private int[] temperatur;                                   

    public Temperaturanzeige(){                                 
        int[] temperatur=new int[24];                           
        for(int i=0; i<temperatur.length;i++){                  
            temperatur[i]=-100;
        }

    }

    public void temperaturEingeben(int tempNeu,int tageszeit){
        temperatur[tageszeit]=tempNeu;
    }

}

Thanks for your answer!

sinclair :
int[] temperatur=new int[24];

Creates a new variable, remove the int[].

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=384929&siteId=1