Results 1 to 3 of 3
  1. #1
    JuliaDavies is offline Member
    Join Date
    Mar 2012
    Posts
    10
    Rep Power
    0

    Default 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

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default 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.

    ** This space for rent **

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: HELP!! NullPointerException - code won't compile

    DOn't double post the same question. I'm closing this thread as the other one has more responses.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. HELP!! Code won't compile - NullPointerException
    By JuliaDavies in forum NetBeans
    Replies: 10
    Last Post: 03-21-2012, 09:29 AM
  2. I cant get my code to compile Need help please
    By MikeJ39 in forum New To Java
    Replies: 6
    Last Post: 10-15-2011, 06:28 AM
  3. Can not compile code , anyone help me fix it ?
    By batista11b5 in forum New To Java
    Replies: 3
    Last Post: 10-22-2010, 02:00 PM
  4. Code does not Compile
    By ustar in forum New To Java
    Replies: 13
    Last Post: 03-06-2010, 04:54 PM
  5. Code will not compile
    By ShotGunRockets in forum New To Java
    Replies: 17
    Last Post: 05-10-2009, 03:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •