• Post Reply Bookmark Topic Watch Topic
  • New Topic

ArrayIndexoutofbounds  RSS feed

 
Michael Nana
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys, I'm working on threads with a 2d array but I am getting this nasty arrayindexoutofbounds exception and I don't understand how I'm getting it.

If I fill that same array with ones without changing the size I don't get the error.

Where's the fault guys ?

Thanks.

 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to post the stack trace and indicate clearly exactly which line is causing it.

Note the ArrayIndexOutOfBoundsException is very straightforward, and the error message even probably tells you what index you were trying to access that doesn't exist.
 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael Nana wrote: . . . I'm working on threads with a 2d array . . .
No, you aren’t. There is no such thing as a 2d array. What you have is an array of arrays.
 
Randall Twede
Ranch Hand
Posts: 4696
8
Java Scala
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you crack me up Campbell
 
Michal Plutynski
Greenhorn
Posts: 14
Eclipse IDE jQuery Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.
maybe it is not common here but I will try to help you.

your problem is here:


as you can see your i will have values 2,52,20 in first 'rowworker'. And you are trying to get aRow[2], aRow[52], aRow[20].

I think that should give you a good idea where is a problem with that code.

I think the good idea will be to read more about 'for-each loop'.

Regards!
 
dennis deems
Ranch Hand
Posts: 808
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michal Plutynski wrote:maybe it is not common here but I will try to help you

Help comes in many flavors. I think the idea was that the OP would post the stack trace generated by the exception, and then could be shown that the trace leads him to that very line. Anyway, great debugging and welcome to the Ranch!
 
Michal Plutynski
Greenhorn
Posts: 14
Eclipse IDE jQuery Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my opinion there is a problem with teaching 'programming' in schools. They never tell you how to deal with problems, how to find out what is an exact cause of a problem. They do not teach you how to debug
From my experience, beginners need more words then only 'stack trace'.

Sorry for that sarcasm in my first reply.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michal Plutynski wrote:In my opinion there is a problem with teaching 'programming' in schools. They never tell you how to deal with problems, how to find out what is an exact cause of a problem.


That's what I was trying to do, by pointing the OP to the stack trace.

From my experience, beginners need more words then only 'stack trace'.


You mean like "even probably tells you what index you were trying to access that doesn't exist"?

I think it's totally reasonable to expect them to spend some time staring at it trying to puzzle out what it means. Especially when they're specifically told that the information they need is there, and what that information will be. Looking at the evidence in front of us, figuring out what it might reasonably mean, and being willing to question our assumptions is the very soul of the art of debugging. It pays to start struggling early, IMHO.
 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Randall Twede wrote:you crack me up Campbell
But lots of people go round thinking they are writing 2D arrays, when they aren’t. People need to use the correct terminology, so we all know what they are talking about. Actually, arrays or arrays are more versatile than 2D arrays, because you can create “jagged” arrays. So saying “array of arrays” reminds you of that advantage.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!