aspose file tools*
The moose likes Beginning Java and the fly likes TicTacToe game help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "TicTacToe game help" Watch "TicTacToe game help" New topic
Author

TicTacToe game help

mike fusc
Greenhorn

Joined: Mar 07, 2010
Posts: 15
[/code]

but after i enter size I always get exception errors here
Exception in thread "main" java.lang.IllegalArgumentException: invalid row index: 3
at TicTacToeBoard.getSquare(TicTacToeBoard.java:25)
at TicTacToe.diagonalComplete(TicTacToe.java:58)
at TicTacToe.gameWon(TicTacToe.java:84)
at TicTacToe.main(TicTacToe.java:116)
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19073
    
  40

mike fus wrote:but after i enter size I always get exception errors here
Exception in thread "main" java.lang.IllegalArgumentException: invalid row index: 3
at TicTacToeBoard.getSquare(TicTacToeBoard.java:25)
at TicTacToe.diagonalComplete(TicTacToe.java:58)
at TicTacToe.gameWon(TicTacToe.java:84)
at TicTacToe.main(TicTacToe.java:116)


That error message, is *your* error message. And it is thrown here....



It may be better if you told us what what was you looking for when you throw that exception?

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
mike fusc
Greenhorn

Joined: Mar 07, 2010
Posts: 15
the TicTacToeBoard.java was not written by me.

The error occurs after i enter the first values of the row and column of x. it doesn't matter what i enter it always gives the exceptions
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19073
    
  40

mike fusc wrote:the TicTacToeBoard.java was not written by me.

The error occurs after i enter the first values of the row and column of x. it doesn't matter what i enter it always gives the exceptions


Regardless, I pointed you to the lines where the error condition is happening. Can you figure it out? It quite simple actually.

Henry
mike fusc
Greenhorn

Joined: Mar 07, 2010
Posts: 15
honestly I'm clueless as to what needs to be fixed.

nothing in tictactoeboard.java can be edited by the way the error has to occur in tictactoe.java
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19073
    
  40

mike fusc wrote:
nothing in tictactoeboard.java can be edited by the way the error has to occur in tictactoe.java



The error *is* in tictactoe.java. And the stack trace should be enough for you to figure out why. And ... if it is not enough to figure it out, I was hoping the hint, to the location in tictactoeboard.java should be enough to figure it out.

Henry
mike fusc
Greenhorn

Joined: Mar 07, 2010
Posts: 15
i think i understand that the error if from having the row set at 0.

now i know the row and column size should be the size i enter for the board to start with but i dont understand what to do to fix it.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19073
    
  40


If you take a look at the exception message (and a quick look at the code), you will see that it is complaining while trying to access something at row index 3. And since Java arrays are zero based, this is the fourth row. Is accessing the fourth row what you wanted?

Henry
mike fusc
Greenhorn

Joined: Mar 07, 2010
Posts: 15
no the problem seems to be with the int size.

whatever variable i enter for size i get the error message at that variable

so like you example of 3 or if i run it and read size at 4 i get Exception in thread "main" java.lang.IllegalArgumentException: invalid row index: 4
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19073
    
  40

mike fusc wrote:no the problem seems to be with the int size.

whatever variable i enter for size i get the error message at that variable

so like you example of 3 or if i run it and read size at 4 i get Exception in thread "main" java.lang.IllegalArgumentException: invalid row index: 4



I gave you a hint to get you to the bug. But you are getting distracted by the fact that this bug occurs no matter what size you entered, which is ... completely your choice. You may see a different bug from the one that I see.

Henry
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40064
    
  28
Welcome to the Ranch

Please don't delete part of your original post; it makes the thread incomprehensible.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: TicTacToe game help