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

  • SEARCH
  • Home
  • 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 8684457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:18:41+00:00 2026-06-12T22:18:41+00:00

I have a 2d array which is of objects of the Node class. This

  • 0

I have a 2d array which is of objects of the Node class. This is the Node class:

public class Node {
private boolean edge;
private int parent;

public Node() {
 edge = false;
    parent = 0;
}

public Node(boolean edge, int parent) {
    this.edge = edge;
    this.parent = parent;
}

public boolean isNode() {
    return edge;
}

public void setNode(boolean node) {
    this.edge = node;
}

public int getParent() {
    return parent;
}

public void setParent(int parent) {
    this.parent = parent;
}
}

And this is my 2d array:

private Node[][] adjMatrix = new Node[x][y];

In a method named addEdge I am trying to set the node at the points i,j in the array to true.

public void addEdge(int i, int j) {
        adjMatrix[i][j].setNode(true);
        adjMatrix[j][i].setNode(true);
}

However I am getting a nullpointerexception on this line and I do not know how to fix it.

adjMatrix[i][j].setNode(true); 

I assume it’s a simple answer that I haven’t been able to find the answer to because I have been looking for awhile. So any help is appreciated.

Thanks a lot 🙂

  • 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-12T22:18:44+00:00Added an answer on June 12, 2026 at 10:18 pm

    You have not instantiated your Nodes inside the list.

    Node[][] adjMatrix = new Node[x][y];
    

    The above statement only initializes your array and does not instantiate the element in it.

    You need to terate through the matrix using for loop, and for each element do: –

    adjMatrix[i][j] = new Node();
    

    You need to do this before using your matrix elements..

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

Sidebar

Related Questions

I have an array which looks like this: $arr = ( [0]=>Int(2) [1]=>Array( ....)
I have an array of objects which all derive from the class BaseStudent. BaseStudent**studentlist
I have an array of DataRow objects in my C# project which I would
I have an array of Deferred objects, which I'm trying to map to their
I have a method which returns an array of fixed type objects (let's say
I have an array which looks like this: $data = array( array('timestamp' => 1312776000,
I have an array which contains 12 numbers and I want to save this
I have a webpage with a slickgrid which renders an array of objects on
I have this XML document <AdditionalParameters> <PublishToPdf Type =System.Boolean>False</PublishToPdf> </AdditionalParameters> in my code and
I have a Array list which contains Objects of Restaurants ArrayList<Restaurants> array_sort = new

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.