• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

TicTacToe game help

 
mike fusc
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[/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
Marshal
Pie
Posts: 21190
80
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
mike fusc
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21190
80
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21190
80
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21190
80
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21190
80
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49379
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Please don't delete part of your original post; it makes the thread incomprehensible.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic