Public Group

#### Archived

This topic is now archived and is closed to further replies.

# java hangman

This topic is 6087 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am trying to make hangman in Java. I have a file set up from which I read from, I then store the individual words in a vector. I have tried to set up a loop that starts at 0 and goes to the word length, while in this loop I will check the letters and display them in the correct place. I can compile and run it, although it seems quite slow, and it also gives me an "Array out of bounds, 0 >= 0" remark. Unfortunately im quite new at this and things also seem to work......in theory. www.geocities.com/toasted_terran/hangman.java www.geocities.com/toasted_terran/hangman_graphics.java (Tell me if you want the source on the forum, if you can''t get to it) cheers

##### Share on other sites
dude, i hope you aren''t trying to get someone to do your homework for you

##### Share on other sites
OF course not, ive been trying to get this to work for about 3 months now.

##### Share on other sites
hmmm sounds fishy to me ( homework) .... I will give you this for advice... read up on Exceptions and create a ''Try'' and ''Catch'' Block ...

  try { //What ever it is your doing } catch {ArrayIndexOutOfBounds yada yada e) { //Whatever you decide to do System.out.println(e); } Finally { //Clean up }

Morpheus

##### Share on other sites
I disagree with a_insomniacs advice in this case. Tho you generally should try to handle exceptions, ArrayIndexOutOfBounds usually shouldn''t be caught this way.

This exception is telling you that there is a fundemental problem with the code and that it should be fixed, not just handled. Handling it will stop the error being shown but it is far better fixing the error.

Check to see if you''re accessing an element beyond the size of the array. Be aware that array indexes usually start at 0, and check your loops to make sure that this is how you are handling it.

However, it is good advice to read up on exceptions even tho it is not applicable in this case

--
SC

##### Share on other sites
quote:
Check to see if you''re accessing an element beyond the size of the array. Be aware that array indexes usually start at 0, and check your loops to make sure that this is how you are handling it.

quote:
I then store the individual words in a vector.

Sorry, I missed the fact that you were using a vector and assumed it was an array, so some of that info was incorrect. However, the advice is still broadly applicable.
--
SC

##### Share on other sites
I appreciate the (limited) help guys. But I think im on to it now. The vector was fine it was something else...

##### Share on other sites
Although vectors start at 0. The charAt and/or elementAt may start their count at 1 (I don''t remember and don''t have the JDK right now).

1. 1
2. 2
3. 3
Rutin
19
4. 4
5. 5

• 10
• 14
• 30
• 13
• 11
• ### Forum Statistics

• Total Topics
631782
• Total Posts
3002338
×