String variable may not have been initialized (error diects to line 34)

前端 未结 4 556
太阳男子
太阳男子 2021-01-26 00:59

I\'ve been trying to get the string initialize, but to no avail. I have tried all of the solutions I have come across and I am not sure whether it is because of my ineptness or

4条回答
  •  遥遥无期
    2021-01-26 01:55

    String computer; // not initialized
    

    change this to

    String computer = null;  or ""// initialized
    if (player.compareTo(computer) == 0)
    

    because, the variable computer will assigned based on the condition. If the above condition you mentioned is not satisfied. The value is none, so only it show the error.

提交回复
热议问题