Array Index Out Of Bounds - Java

前端 未结 2 719
迷失自我
迷失自我 2021-01-24 23:23

I have started to work on my first Java program, which is a simple calculator, however I get an error claiming that my array is out of bounds. I have tried to debug it to see wh

2条回答
  •  粉色の甜心
    2021-01-25 00:05

    You are only ever adding one item to your list:

    currentNum = Double.parseDouble(currentString);
    outputNum.add(currentNum);
    

    Then you try to access what seems to be a second object at index operationindex +1 which doesn't exist:

    answer = outputNum.get(operationIndex) * outputNum.get(operationIndex+1);
    

提交回复
热议问题