• Post Reply Bookmark Topic Watch Topic
  • New Topic

Multiply 3D matrix  RSS feed

 
nvayin agha
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The java code bellow is for multiplying 3D arrays , iam receiving error , please any suggestion.





ERROR is :

ArrayIndexOutof Bound. ??

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException
 
Liutauras Vilda
Sheriff
Posts: 4917
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

nvayin agha wrote:iam receiving error , please any suggestion.
As a first suggestion - please post a full error message (copy/paste).
 
Liutauras Vilda
Sheriff
Posts: 4917
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is in this line:
Particularly in this part arr3D[s][u][d]

u goes up to index 3, while that part where u appears has only 3 elements in it, which is max index is 2.

It is confusing as hell, right? Guess why?
 
nvayin agha
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Iam sorry i do not now why, yes "u" goes for 2 ??
 
Liutauras Vilda
Sheriff
Posts: 4917
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nvayin agha wrote:Iam sorry i do not now why, yes "u" goes for 2 ??
No, u max value is 3.

arr3D[s][u][d]; <--- in that bold part (dimension) u index goes out of bounds when u index is greater than 2, because you have 3 rows in total, and that middle index represents rows in your model.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!