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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T02:11:17+00:00 2026-06-19T02:11:17+00:00

I’ve been scouring the 1000’s of NullPointerException posts on stackoverflow and cannot for the

  • 0

I’ve been scouring the 1000’s of NullPointerException posts on stackoverflow and cannot for the life of me figure why this is happening; aside from the obvious (that it is null). Can someone help me understand what it is that I am not understanding about Generic Singly LinkedList that is causing me to get this run time error.

Here is my code:

    import java.io.*;
    import java.util.*;

public class GList<T> {         
    private GNode<T> head;
    private GNode<T> cursor;

    private static class GNode<E>{
    private E data;        //NULLPOINTEREXCEPTION
    private GNode<E> next;

    public GNode(E data, GNode<E> next) {
        this.data = data;
        this.next = next;
    }
}                
public static class InnerList<E> {
    private String name;
    private GList<Integer> inner = new GList<Integer>();

    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public GList<Integer> getInner() {
        return inner;
    }
    public void setInner(GList<Integer> inner) {
        this.inner = inner;
    }
}
public boolean hasNext(T cursor) {
    /*
     * returns whether or not the node pointed to by 'cursor' is
     * followed by another node. If 'head' IS null, returns False
     */
    if (cursor != null)
    {
        return true;
    }
    else
    {
        return false;
    }
}
public void insertFirst(T t) {
    /*
     * puts a new node containing t as a new first element of the list
     * and makes cursor point to this node
     */     
    if (hasNext(t) == false){
        head = new GNode<T>(t, head);
        head.next.data = t;
        cursor.next = head;
    }
    else{
        System.out.println("List is not null.");
    }
} 
public static void main(String[] args){

GList<InnerList> list = new GList<InnerList>();

String ln = "hello";
list.cursor.next.data.setName(ln);  //NULLPOINTEREXCEPTION

/*Exception in thread "main" java.lang.NullPointerException
 *at GList$GNode.access$0(GList.java:10)
 *at GList.main(GList.java:67) 
 */
}
}

This is homework, so an explanation would be most helpful as I am sure I will be dealing with LinkedList throughout the coming months.

  • 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-19T02:11:18+00:00Added an answer on June 19, 2026 at 2:11 am

    Since you are using the default constructor, for which you haven’t given an implementation

    GList<InnerList> list = new GList<InnerList>();
    

    None of its fields are being initialized and so

    list.cursor == null
    

    Java stops execution here, but your other fields are also null. Take the time to revisit your code and initialize all the relevant fields.

    The fact is you shouldn’t try to access anything in your list since you haven’t added any items to it. Its head and cursor are null.

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.