Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Convert 1d array to 2D boolean

 
Nattakan Lukkanapinit
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a set of String and would like to convert to 2d array of boolean
I have an error at line 38 and 32.
This is my String
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34839
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nattakan Lukkanapinit wrote:I have an error at line 38 and 32.

What is the error?
 
Nattakan Lukkanapinit
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne Boyarsky wrote:
Nattakan Lukkanapinit wrote:I have an error at line 38 and 32.

What is the error?


Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 13
at test.main(test.java:34)
 
Sunil Kumar
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have quiet a few problems here
Line 32 : You are iterating on the string array(of length 13) using the length of corresponding element of the array(38). Clearly, when you reach at 13 on str_data[z], it will throw ArrayIndexOutOfBounds
You can fix the above by using str_data.length, but your code piece wouldnt return the desired results. You need to work more on it. I wouldnt want to mention the problems until you give it a try.
 
Nattakan Lukkanapinit
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sunil Kumar wrote:You have quiet a few problems here
Line 32 : You are iterating on the string array(of length 13) using the length of corresponding element of the array(38). Clearly, when you reach at 13 on str_data[z], it will throw ArrayIndexOutOfBounds
You can fix the above by using str_data.length, but your code piece wouldnt return the desired results. You need to work more on it. I wouldnt want to mention the problems until you give it a try.

thanks for everyone who help me.
ok i fixed all the problem and the program can run without error


this is output of my test program just in main


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic