![]() |
|
#1
|
|||
|
|||
Classic recursion game of 8 Queens errorsHey I am a relatively amateur java programmer using Eclipse. I have been trying for a while now to create the classic recurrsion game of 8 Queens and am stumped. Here is what I have so far:
JAVA Code:
And a class: JAVA Code:
I'm getting no luck with a bunch of different errors every time i try to change something. Can someone please help? Last edited by admin II : 27-May-2008 at 04:32.
Reason: Please surround your Java code with [java] your code [/java]
|
|
#2
|
||||
|
||||
Re: Having trouble...need some helpQuote:
Post the errors that you get so that we can see where the problem(s) may be. It might be helpful to check this post, or this post for troubleshooting Java errors. Also, with future Jave code, paste the codes between [java] [/java] tags. __________________
Use the force...read the source!! WYCIWYG -- what you code is what you get! |
|
#3
|
|||
|
|||
Re: Having trouble...need some helpThe error that i initially get before I change anything is
Exception in thread "main" java.lang.NullPointerException at queens.Queens.main(Queens.java:17) which refers to the print statement |
|
#4
|
|||
|
|||
Re: Having trouble...need some helpThis would be my guess:
JAVA Code:
|
|
#5
|
||||
|
||||
Re: Having trouble...need some helpQuote:
fakepoo has already made reference to the offending line. Also, see this post for a stack dump trace example. (different situation, but they also had a "null pointer" problem) __________________
Use the force...read the source!! WYCIWYG -- what you code is what you get! |
|
#6
|
|||
|
|||
Re: Having trouble...need some helpIt still gives me the same error.
Is there a different way to output it just to see if the program is working...then I will worry about properly printing it out |
|
#7
|
|||
|
|||
Re: Having trouble...need some helpProbably what is happening is with this:
JAVA Code:
|
|
#8
|
|||
|
|||
Re: Classic recursion game of 8 Queens errorshey i reformatted the program to make it more basic, using an 8 X 8 array and such and am getting there but am still gettting a common error. Here is the code:
JAVA Code:
the error i keep getting even when i change up the code, its an index out of bounds error, usually from a -1 or an 8, and im not sure why: Code:
and Code:
Hope you guys can help because im stumped Last edited by admin : 01-Jun-2008 at 06:33.
Reason: Please insert your example Java codes between [JAVA] and [/JAVA] tags
|
|
#9
|
||||
|
||||
Re: Classic recursion game of 8 Queens errorsThe number with the 'out-of-bounds' is the index value that is out of range.
The array is specified 8, so that is the range 0 through 7, of course. In both cases, though, it seems that the handling between functions 'placeQueen' and 'canBePlaced' is causing a problem. Add some print functions to show the calculations of the row and column values as it proceeds -- that should lead to the problem. Here's an example for the -1: Code:
If you get stumped again, post another reply. __________________
Use the force...read the source!! WYCIWYG -- what you code is what you get! |
|
#10
|
||||
|
||||
Re: Classic recursion game of 8 Queens errorsQuote:
There's also the good old pencil and paper [aka: by hand] method to "trace-out" or plan the logic, and it's usually better to start that way. __________________
Use the force...read the source!! WYCIWYG -- what you code is what you get! |
Recent GIDBlog
US Elections and the ?Voter?s Responsibility? by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| C++ Function Trouble(I'm having trouble with my program). | dmb2140 | C++ Forum | 2 | 25-Nov-2007 10:27 |
| Having trouble with body of programs | Mrsnap32 | C++ Forum | 2 | 05-Apr-2006 08:08 |
| Trouble with files and array linking to files. | Blstretch | C Programming Language | 14 | 03-Dec-2005 04:29 |
| C programming trouble | Newworld | C Programming Language | 8 | 13-Sep-2004 00:06 |
| Having trouble trying to format C: | Nickster64 | Computer Software Forum - Windows | 2 | 27-Jul-2004 08:31 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The