Results 1 to 3 of 3
- 03-19-2012, 06:14 PM #1
Member
- Join Date
- Mar 2012
- Posts
- 10
- Rep Power
- 0
HELP!! NullPointerException - code won't compile
Hi, please can someone help me!
My code won't compile and the error thrown is NullPointerException.
The two lines of code it says are null are:
public SwingSudokuBoard(int[][] board) {
this(board.length); <-----THIS ONE
for (int row = 0; row < size; row++) {
for (int col = 0; col < size; col++) {
setCell(board[row][col], row, col);
}
}
}
public SwingSudokuBoard(int size) {
super(size);
cells = new TextField[size][size];
panel.setLayout(new GridLayout(size, size));
for (int row = 0; row < size; row++) {
for (int col = 0; col < size; col++) {
panel.add(cells[row][col]); <-----THIS ONE
}
}
How do I make them not Null? Or please can anyone explain to me why they are being thrown as errors?
I initialised panel here: private JPanel panel = new JPanel(); at the beginning of the class SwingSudokuBoard (which extends SudokuBoard)
and I initialised board here:
public SudokuBoard(int[][] board) {
this(board.length);
this.board = board;
} in SudokuBoard class
I initialised cells in the same method as above: cells = new TextField[size][size];
Does length need to be initialised? Is this where I am going wrong?
Thank you
Julia
- 03-19-2012, 06:24 PM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,451
- Rep Power
- 16
Re: HELP!! NullPointerException - code won't compile
You really do need to use [code] tags[/code].
Which of those lines is the one throwing the exception.
And, since this is a new thread, you ought to post the stack trace here.Please do not ask for code as refusal often offends.
- 03-19-2012, 06:40 PM #3
Similar Threads
-
HELP!! Code won't compile - NullPointerException
By JuliaDavies in forum NetBeansReplies: 10Last Post: 03-21-2012, 09:29 AM -
I cant get my code to compile Need help please
By MikeJ39 in forum New To JavaReplies: 6Last Post: 10-15-2011, 06:28 AM -
Can not compile code , anyone help me fix it ?
By batista11b5 in forum New To JavaReplies: 3Last Post: 10-22-2010, 02:00 PM -
Code does not Compile
By ustar in forum New To JavaReplies: 13Last Post: 03-06-2010, 04:54 PM -
Code will not compile
By ShotGunRockets in forum New To JavaReplies: 17Last Post: 05-10-2009, 03:31 AM


LinkBack URL
About LinkBacks

Bookmarks