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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:21:47+00:00 2026-06-13T03:21:47+00:00

So I need a linked list to store multiple variables, so I want to

  • 0

So I need a linked list to store multiple variables, so I want to use my hand-made Linked List ADT, but also want Java’s Linked List’s Comparator Sort from collections.sort();

So I tried and edited my code as following:

public class HLinkedList <HTreeNode>  extends LinkedList <HTreeNode>
{

public class HTreeNode {


    public HTreeNode left;
    public HTreeNode right;
    public HTreeNode next;
    public int frequency;
    public char value;
    public String code;
    public HTreeNode(int freq, char val, HTreeNode l, HTreeNode r, HTreeNode n, String code) // code is the path taken to this node, how to explain it in code?
    {
        value = val;
        frequency = freq;
        left = l;
        right = r;
        next = n;
        code = ""; // just initialized ,but have to think through logic.
    }
}

but if I do this, instead of just public class HLinkedList (which is fine except I can’t use Collections.sort(HList, comparatorA), one line of code that I need to have Java’s Linked List for.

anyways, if I have my code as shown above it returns a

cannot make static reference to non-static type HTreeNode in following line, 

with red lining under HTreeNode. This does not happen if I do not try to extend LinkedList.

public static void insertIntoPosition(HTreeNode node, int position)

also following the above error is an error in

public HLinkedList() //constructor
{
    head = null; //inital value
    nItem = 0;//counter

}

where multiple occurences in the code indicate they cannot static reference a non-static head. Usually when stuff like this comes up I click “make that head static”, but in this case when I do that even more errors pop up, now pointing to ALL the “head” references.

I would just like to know what is going on when I am trying and failing at extending LinkedList, or if I’m supposed to not extend but do something else maybe?

  • 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-13T03:21:48+00:00Added an answer on June 13, 2026 at 3:21 am

    The following method is a class method:

     public static void insertIntoPosition(HTreeNode node, int position)
    

    Thus it does not need an instance of HLinkedList in order to be invoked.

    However, your class HTreeNode is an inner class – and need an “attahced” instance of HLinkedList in order to be instantiated.

    These two facts contradict each other (you cannot instantiate an object of this type in this method)

    You can add the static keyword to the declaration of HTreeNode in order to overcome this:

    public static class HTreeNode { //note the static keyword usage
        ....
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working with a linked list in java and I need to take a
I need to store a recursive tree structure. A linked list. So all the
I need to make a linked list that stores integer data. Also the list
Due to specific requirements [*], I need a singly-linked list implementation that uses integer
I need to access the HashMap key elements much like a linked list with
I've already created the Binary Tree and Linked list classes, I'm just in need
For an assignment, I need to add one objects linked list to the back
I need to copy two linked lists recursively and return a new list .
I need to be able to store a large list of ordered items in
I need to create a completely generic linked list that can contain any type

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.