• Post Reply Bookmark Topic Watch Topic
  • New Topic

Array Index Returns Error  RSS feed

 
Ranch Hand
Posts: 1785
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following returns this error:

[9/5/14 9:33:33:051 CDT] 00000024 SystemOut O checkItemLookupHistory
[9/5/14 9:33:33:051 CDT] 00000024 SystemOut O 861272-479A , 861405-013N
[9/5/14 9:33:33:051 CDT] 00000024 SystemOut O checkItemLookupHistory: i: 0
[9/5/14 9:33:33:051 CDT] 00000024 SystemOut O AbstractFAIStatusIndentedBill_Type3: setIntdentedBill: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0


 
Bartender
Posts: 2087
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your inner ArrayList is empty. So, when you try to get an item at index 0 you experience the exception.

By the way, it would be better to iterate over a collection using for-each loop.
 
Steve Dyke
Ranch Hand
Posts: 1785
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paweł Baczyński wrote:Your inner ArrayList is empty. So, when you try to get an item at index 0 you experience the exception.

By the way, it would be better to iterate over a collection using for-each loop.


Doesn't line #2 of the SystemOut show that there is a value for this specified array element?
 
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steve Dyke wrote:
Doesn't line #2 of the SystemOut show that there is a value for this specified array element?


Can you tell us what is line #2? ... all I see is a printout of a string at that location. There is no reference to an array, or any of its elements.


And BTW, it would probably be a good idea to provide a stack trace, instead of just printing out the exception condition. It is very difficult to determine the location without it.

Henry
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That depends where your exception is being thrown from. You haven't told us that. And the fourth line of the output doesn't appear to have been by any of the code you're showing either, so maybe you're not showing us the relevant code?
 
Rancher
Posts: 3742
16
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steve Dyke wrote:Doesn't line #2 of the SystemOut show that there is a value for this specified array element?

That's the output the first time through the loop, when i is 0.
The exception is being thrown the second time through the loop, when i is 1. It's the call to get(0) in the print statement that's causing the exception.
 
Steve Dyke
Ranch Hand
Posts: 1785
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My issue is else where in my code.

I am declaring a counter variable
int counter = 0

I pass the variable into a method where I do counter++ but the counter value that it was passed from remains 0
 
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
without seeing your code, my guess is that you are confused about what is passed into the method. You are not passing in the VARIABLE. You simply pass in it's VALUE, which gets stored in a new variable. withing the method, you can change the value all you want, but it would have no affect on the variable outside the method.

Think of it this way...I have a piece of paper with a number written on it. I tell you "my number is 0". you write that down on your piece of paper. You then erase your 0, and write '1'. Then you say "OK...I'm done".

My piece of paper still has 0 on it. I do not know what you did with your copy.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!