Jump to content

Local variable x is never read.

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
hetra

hetra

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 298 posts
Hello all,

I was watching a Java tutorial on YouTube about variable arithmetic. So I thought I'd make a simple programm to take two variables and do arithmetic on them. So I declare an int variable x. Then this happens:

I hover the mouse and it says "Local variable x is never read". What is this?

[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]
[LEFT]public[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]class[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Variable_Arithmetic {

[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][/COLOR][/SIZE][/COLOR][/SIZE][/B] 
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]         public[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]static[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] main(String[] args) {

[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][/COLOR][/SIZE][/COLOR][/SIZE][/B] 
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]                     int[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [U]x[/U] = 10;


}

}[/LEFT]
[/SIZE]

I am using Eclipse for whatever it's worth.

Help would be great.

#2
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
It's just a 'warning' probably because you declare x. But you don't do anything useful with it. If below you say
System.out.println(x);
then it's most likely solved as eclipse notices that x is now used and useful in some way.

#3
hetra

hetra

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 298 posts
Oh Thanks