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 6614833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:23:12+00:00 2026-05-25T20:23:12+00:00

we are learning about linked list using nodes and I’m not sure if i’m

  • 0

we are learning about linked list using nodes and I’m not sure if i’m doing this right. We are suppose to just make a simple list but when I go to run the program, I’m getting nullpointerException pointing to showList() method but when I try to not use that method, then nothing prints out at all. Please any help is greatly appreciated.

 public class node {
      public int dataitems; 
      public node next; 
      node front;

public void initList(){
    front = null;
}

public node makeNode(int number){
    node newNode;
    newNode = new node();
    newNode.dataitems = number;
    newNode.next = null;
    return newNode;
}

public boolean isListEmpty(node front){
    boolean balance;
    if (front == null){
        balance = true;
    }
    else {
        balance = false;
    }
    return balance;

}

public node findTail(node front) {
    node current;
    current = front;
    while(current.next != null){
        //System.out.print(current.dataitems);
        current = current.next;

    } //System.out.println(current.dataitems);
    return current;
}

public void addNode(node front ,int number){
    node tail;
    if(isListEmpty(front)){
        front = makeNode(number);
    } 
    else {
        tail = findTail(front);
        tail.next = makeNode(number);
    }
}

public void printNodes(int len){

    int j;
    for (j = 0; j < len; j++){
        addNode(front, j);
    }  showList(front);
}

public void showList(node front){
    node current;
    current = front;
    while ( current.next != null){
        System.out.print(current.dataitems);
        current = current.next;
    }
    System.out.println(current.dataitems);
}


public static void main(String[] args) {
     node x = new node();

     x.printNodes(50);
    } 

       }
  • 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-05-25T20:23:12+00:00Added an answer on May 25, 2026 at 8:23 pm

    The problem has to do with the variable scoping of your addNode method.

    public void addNode(node front ,int number){
        node tail;
        if(isListEmpty(front)){
            front = makeNode(number); //reassigns the node front parameter
        } 
        else {
            tail = findTail(front);
            tail.next = makeNode(number);
        }
    }
    

    Your assignment of “front” only assigns the makeNode(number) value to the local variable. You need to use this.front to assign the makeNode(number) to the instance variable of your node class or refactor your variable name.

    public void addNode(node front ,int number){
        node tail;
        if(isListEmpty(front)){
            //assigns a value to the member variable "front" of your node instance
            this.front = makeNode(number); 
        } 
        else {
            tail = findTail(front);
            tail.next = makeNode(number);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm just learning about SVG, and it seems great but I'm not sure about
I've just started learning about parsing, and I wrote this simple parser in Haskell
I've just been learning about master pages in ASP.NET 2.0. They sound great, but
I am just learning about app.config in respect of creating custom sections. I have
I am just now learning about function pointers and, as I was reading the
I'm just learning about MSBuild and I'm wondering what are some useful tasks people
Just learning about Dependency Injection and Prism... It seems just asking around alot of
Just learning about sql joins and things, and I have a question. Can you
I just started learning C++ couple of weeks ago. So now I have this
I'm just learning C++ and started using different libraries, like Boost and SDL. After

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.