Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9153455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:16:30+00:00 2026-06-17T12:16:30+00:00

Possible Duplicate: objects classes and arrays – why is it returning ‘null’ ? [java]

  • 0

Possible Duplicate:
objects classes and arrays – why is it returning ‘null’ ? [java]

The other questions with similar titles all have the answer that their data needs to be initialized which I have done but I’m still getting a null pointer exception. Could anyone tell me why?

    public class grid{
private Node [][] board = new Node [9][9];

public boolean add(int x, int y, char label) {
    boolean valid=true;

    System.out.println("enter add");
    if(label==' '){
        System.out.println("enter if 1");
        board[x][y].setValue('0');
    }
    else if(label<='9'&&label>'0'){
        System.out.println("enter if 2");
        board[x][y].setValue(label);
    }
    else{
        valid=false;
    }
    if(valid)
        System.out.println("valid");
    return valid;
}

I’m getting the error on the setValue Lines (10 and 14)

    public class Node{
public char value;
public char []  possibleValues = {1,2,3,4,5,6,7,8,9};
public boolean correct=false;
    }

Edit: I figured it out, if anyone else has the same problem, this seems to fix it.

    if(label==' '){
        System.out.println("enter if 1");
        board[x][y]= new Node(' ');
    }
    else if(label<='9'&&label>'0'){
        System.out.println("enter if 2");
        board[x][y]= new Node(label);
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T12:16:31+00:00Added an answer on June 17, 2026 at 12:16 pm

    An array does not initialize the elements of the array. So, each board[x][y] will be initially null.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Sorting Java objects using multiple keys I have an employee class. Based
Possible Duplicate: How are Anonymous (inner) classes used in Java? i have a question
Possible Duplicate: How to properly clean up Excel interop objects in C# I have
Possible Duplicate: Object destruction in C++ Suppose we have two classes, one is called
Possible Duplicate: Sorting Java objects using multiple keys I can't find any example of
Possible Duplicate: How to Serialize an ArrayLIst in java without getting errors? I have
Possible Duplicate: Activator.CreateInstance - How to create instances of classes that have parameterized constructors
Possible Duplicate: java class declaration <T> Sometimes I've seen that java classes are created
Possible Duplicate: What is an interface in Java? I have experience with object languages
Possible Duplicate: Creating generic arrays in Java I want to trim a generic array

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.