Jump to content
  • Advertisement

Archived

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

Toasted

java hangman

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
Share on other sites
Guest Anonymous Poster
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 this post


Link to post
Share on other sites
Guest Anonymous Poster
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 this post


Link to post
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 this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!