*
The moose likes Beginning Java and the fly likes Out of bounds exception in code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Out of bounds exception in code" Watch "Out of bounds exception in code" New topic
Author

Out of bounds exception in code

Gabriel White
Ranch Hand

Joined: Mar 02, 2003
Posts: 233
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

Joined: Nov 24, 2005
Posts: 14688
    
  16

You should check the length of the date before checkDate.charAt(1).
If checkDate is empty, it will throw an exception.


[My Blog]
All roads lead to JavaRanch
Gabriel White
Ranch Hand

Joined: Mar 02, 2003
Posts: 233
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

Joined: Nov 24, 2005
Posts: 14688
    
  16

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

Joined: Aug 05, 2005
Posts: 3682
    
  16


[/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 ]

Joanne
Gabriel White
Ranch Hand

Joined: Mar 02, 2003
Posts: 233
Thanks.
 
 
subject: Out of bounds exception in code