• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Array Index Returns Error

 
Ranch Hand
Posts: 2211
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2236
63
IntelliJ IDE Firefox Browser Spring Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2211
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2211
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic