Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Errors with game board tester ConnectFour, TicTacToe, MasterMind

 
Danny Broadwater
Ranch Hand
Posts: 55
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Tony Docherty
Bartender
Posts: 2989
59
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ole Sandum
Ranch Hand
Posts: 65
1
IntelliJ IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is shown above is not a local class, nor is it used like one.
 
Ole Sandum
Ranch Hand
Posts: 65
1
IntelliJ IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 55
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The error is

 
Tony Docherty
Bartender
Posts: 2989
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 55
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the Board class

 
Danny Broadwater
Ranch Hand
Posts: 55
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the error is

 
Tony Docherty
Bartender
Posts: 2989
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 55
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2989
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 55
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your time all the help. It is working correctly now.
Thanks again
 
Tony Docherty
Bartender
Posts: 2989
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My pleasure
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic