wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Errors with game board tester ConnectFour, TicTacToe, MasterMind Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Errors with game board tester ConnectFour, TicTacToe, MasterMind" Watch "Errors with game board tester ConnectFour, TicTacToe, MasterMind" New topic
Author

Errors with game board tester ConnectFour, TicTacToe, MasterMind

Danny Broadwater
Ranch Hand

Joined: Sep 29, 2013
Posts: 55

I am new to Java. Here is my project, problem is the game will not claims I have errors. will you please help me figure out the errors. All it is suppose to do is print out the game boards. Thanks for your time.



Lost in the 60's
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2170
    
  47
Welcome to the Ranch.

When adding code tags, you have to highlight all the code before clicking the code button, I've fixed the code tags for you this time.

Please can you tell us what the errors are ie cut and paste the compiler/runtime error messages into a post here. It's hard to fix something when we've no idea what is wrong with it and personally I don't have the time or the Board class to be be able to test your code myself.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41089
    
  44
For starters, you're trying to declare a class inside of a method (the main method) - that is not possible. The code is also missing a closing "}", but I guess that may just be a copy/paste error.


Ping & DNS - my free Android networking tools app
Ole Kristian Sandum
Greenhorn

Joined: Sep 27, 2013
Posts: 15
Ulf Dittmer wrote:For starters, you're trying to declare a class inside of a method (the main method) - that is not possible. The code is also missing a closing "}", but I guess that may just be a copy/paste error.


Declaring a class inside a method is possible, and it's called a local class.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41089
    
  44
What is shown above is not a local class, nor is it used like one.
Ole Kristian Sandum
Greenhorn

Joined: Sep 27, 2013
Posts: 15
Ulf Dittmer wrote:What is shown above is not a local class -snip-

Really? Well, according to this, it seems like a local class to me:
http://docs.oracle.com/javase/tutorial/java/javaOO/localclasses.html

I do agree, of course, that the OP is not using it correctly, as, to be able to use it, they would have had
to define it above where they are referencing it, in the same block as they are referencing it. What this means
is that they are actually referencing the Board class they imported, not the one they defined at the bottom of
the method. I have no clue why they would define a local class called Board in the first place, if they already
have an external class of the same name, which is probably the class they want to use.
Danny Broadwater
Ranch Hand

Joined: Sep 29, 2013
Posts: 55

The error is

Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2170
    
  47
That only the first line of the error message, the stack trace is genearlly also required to tell us where the error is. Having said that you only have one place in your code where you are using arrays so I assume it is there.

The problem is in the outer loop

You should be iterating whilst r1 is less than cells.length.
Danny Broadwater
Ranch Hand

Joined: Sep 29, 2013
Posts: 55

Here is the Board class

Danny Broadwater
Ranch Hand

Joined: Sep 29, 2013
Posts: 55

the error is

Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2170
    
  47
Even though the error is in a different class to the one you originally posted my explanation of what the error is was correct. Read my earlier post and look at line 21 in the board class.
Danny Broadwater
Ranch Hand

Joined: Sep 29, 2013
Posts: 55

thanks,

at line 21 in the board class I changed it to read



now I am getting the error of



I am at a total loss here
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2170
    
  47
at line 21 in the board class I changed it to read

Sorry I said to look at line 21 but I should have said line 19, although if you had read my description of the error in the earlier post I'm sure you would have worked that out.

I don't understand why you would change line 21 to a print statement - do you mean you inserted a print statement?
If you removed the array initialization then you would get NullPointerExceptions elsewhere in your code.
Danny Broadwater
Ranch Hand

Joined: Sep 29, 2013
Posts: 55

Thank you for your time all the help. It is working correctly now.
Thanks again
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2170
    
  47
My pleasure
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Errors with game board tester ConnectFour, TicTacToe, MasterMind
 
Similar Threads
problem drawing TicTacToe
TicTacToe Game..
connect 4 and two dimensional arrays
Game Tutorials -->> TicTacToe
TicTacToe game