I made a calculator that does the basic operations but I want to be able to divide more than two numbers by repeatedly entering values using an arraylist and I keep getting the indexoutofboundsexception and I don't know why? I understand the reason behind the outofboundsexception but I can't figure out why in this case. Please excuse me, its my first time here. Any help is appreciated. Here is a snippet:
The problem is with numList.get(i+1).
You iterate i variable from 0 to numList.size()-1.
When you invoke numList.get with value numList.size() (calculated from numList.size()-1 + 1) you get the exception.
Hello, and welcome to JavaRanch!
Kudos for using code-tags in your first post, but you didn't actually place the code inside them, so I went ahead and fixed that for you
Now for the problem, one source of a possible IndexOutOfBoundsException is the get() call at line 3 if the list is empty.
Two other possible sources can be found inside the body of the for-loop when it reaches the last iteration.
Ps. I'm assuming that list and numList actually should be the same reference and this is a copy-paste error?
Edit: Awww, too late.
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.