• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Out of bounds exception in code

 
Gabriel White
Ranch Hand
Posts: 233
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey yall, just wanted to post something up here real quick to see if I can get some more eyes on it. I have code that is throwing an out of bounds exception and it is for a program that accepts appointments into a ragged array. The ragged parts are the columns representing the days of the months. I digress. When I try to overwrite a pre-existing appointment I have it prompt me to overwrite and then bam!

I noted the line number where it is thrown.



Here is were it is called to overwrite and tossed in as a parameter:



at raggedArray.isDateValid(raggedArray.java:134)
at raggedArray.setAppointment(raggedArray.java:238)

Thanks in advance

Gabe
 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should check the length of the date before checkDate.charAt(1).
If checkDate is empty, it will throw an exception.
 
Gabriel White
Ranch Hand
Posts: 233
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, well maybe I didn't find the problem.

Now its a new one.

When I hit 'Y' instead of 'y' it works so this must be part of the problem:



can you not do a bufferedReader or statement for chars? it is obviously just reading in the first char I enter and not even checking the if statement.

I even tried to read them in as strings. I do not want to use the console class for this.

Does anyone have any suggestions. I know this is totally easy thats why its in the beginner section

Thanks

[ April 10, 2006: Message edited by: Gabriel White ]
[ April 10, 2006: Message edited by: Gabriel White ]
 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I hit 'Y' instead of 'y' it works so this must be part of the problem


You're not calling your buggy isDateValid() function, that's all.

About the BufferedReader, why don't you store the returned character ?
 
Joanne Neal
Rancher
Pie
Posts: 3742
16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


[/qb]<hr></blockquote>

This reads the first character and checks if it is 'Y' and then reads the next character before checking if it is 'y'. Store the first character as Satou suggested and check that instead.
[ April 10, 2006: Message edited by: Joanne Neal ]
 
Gabriel White
Ranch Hand
Posts: 233
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic