IndexOutOfBoundsException with AWT-EventQueue-0
I'm writing a calculator and for some reason whenever I hit the + sign this error gets thrown
Exception in thread "AWT-EventQueue-0" java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.RangeCheck(Unknown Source)
at java.util.ArrayList.remove(Unknown Source)
at gui.LongInteger.addition(LongInteger.java:78)
at gui.Calculator$3.actionPerformed(Calculator.java:1 42)
My addition listener is this
Code:
//textField is a TextField object
//output is a StringBuilder object
buttonPlus.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
currentEntry = new LongInteger(output.toString());
currentValue = currentValue.addition(currentEntry);
textField.setText(currentValue.toString());
output.delete(0, output.length());
}
});
the code within my addition method that messes up is
Code:
num1 = Integer.parseInt(this.arrayIntList.remove(0).toString());
and here is the constructor for a LongInteger
Code:
LongInteger(String input){
if((input.charAt(0) == '-') || (input.charAt(0) == '+')){
if(input.charAt(0) == '-')
isPositive = false;
input = input.substring(1);
}
for(int i = 0; i < input.length(); i++){
char temp = input.charAt(i);
String tempString = new String(temp+"");
this.arrayIntList.add(Integer.parseInt(tempString.trim()));
}
this.size = arrayIntList.size();
}
can anybody explain why this is happening?