Why am I getting a “cannot find symbol” error in my java program when I compile?

后端 未结 2 1359
死守一世寂寞
死守一世寂寞 2021-01-26 13:31

I am trying to return the value of my boolean variable localFound at the end of my code but when I compile, I get an error that says it cannot find the symbol. I know this is a

相关标签:
2条回答
  • 2021-01-26 13:44

    The localFound variable is declared within the if statement, thus, it's not visible outside that statement. Try declaring it right before the if statement (outside it) and you'll get the code compiling.

    0 讨论(0)
  • 2021-01-26 14:00

    localFound is not defined in the scope of your return statement. It only exists within your if statement.

    Move the declaration outside of your if statement, and initialize it to some default value, such as false.

    0 讨论(0)
提交回复
热议问题