ThisGuy
ThisGuy

Reputation: 873

error: int cannot be dereferenced in java

I'm having an error called 'int cannot be dereferenced' on these lines of code. Errors point at all indices containing i, why? Any help would be much appreciated.

    for(i=0;i<5;i++){
        if(e.getSource()==ui.lights[0][i]){
            ui.lights[0][i].setText("X");
            if(lights[1][i].getText()!=""){
                lights[1][i].setText("X");
            }
            if(i-1>=0){
                if(lights[0][i-1].getText()!="X")
                    lights[0][i-1].setText("X");
            }
            if(i+1<=4){
                if(lights[0][i+1].getText()!="X")
                    lights[0][i+1].setText("X");
            }
        }
    }

Upvotes: 0

Views: 192

Answers (1)

sandymatt
sandymatt

Reputation: 5612

ui.lights[0][i].setText("X");

int is a primitive type. it is not an object. it does not have methods.

when you're calling .setText(), you're assuming that ui.lights[0][i] is an object that has that method. but from your description, it seems that it's just an int.

Either that, or ui itself is just an int.

Upvotes: 2

Related Questions