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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:09:04+00:00 2026-06-05T04:09:04+00:00

I was designing a generic linked list to create a linked list of Strings.

  • 0

I was designing a generic linked list to create a linked list of Strings.
However I keep getting this error :

Exception in thread "main" java.lang.NoSuchMethodError: Node.<init>(Ljava/lang/Object;)V
at LinkedList.addNode(LinkedList.java:10)
at LinkedList.<init>(LinkedList.java:22)
at Trial.main(Trial.java:7)

From the stack trace , the error is generated at LinkedList’s addNode() method. Im including the definition to this method as well as the definition of the Node class.
LinkedList addNode()

public void addNode(T n) {
        Node<T> temp = new Node<T>(n);
        if(start==null) {
            start = temp;
            current = start;
        } else {
            end.setNext(temp);
        }
        end =temp;
    }

Node.java

public class Node<T>{
private T n;
Node next;
Node(T n) {
    this.n = n;
    next = null;
}
public void setNext(Node nextNode) {
    next = nextNode;
}
public Node getNext() {
    return next;
}
public T getN() {
    return n;
}
@Override
public String toString() {
    if(n instanceof String)
        return n.toString();
    else {
        return T.toString();
    }
}

}

LinkedList.java

public class LinkedList<T>{
Node start;
Node end;
Node current;
private static final long serialVersionUID = 901L;
    LinkedList(T n) {
        addNode(n);
    }
    public void addNode(T n) {
        Node<T> temp = new Node<>(n);
        if(start==null) {
            start = temp;
            current = start;
        } else {
            end.setNext(temp);
        }
        end =temp;
    }

    LinkedList(T[] n) {
        for(T print : n)
        addNode(print);
    }
    public void addNode(T[] n) {
        if(n!=null) {
            for (T values : n) {
                addNode(values);
            }
        }
    }

    public void incC() {
        current = current.getNext();
    }
    public void insert(T n) {
        Node newNode = new Node(n);
            if(current==start){
                newNode.setNext(current);
                start = newNode;
            }else {
                Node tempstart = start;
                Node prevAdd=null;
                while(tempstart!=current){
                    prevAdd = tempstart;
                    tempstart = tempstart.getNext();
                }
                prevAdd.setNext(newNode);
                newNode.setNext(current);
            }
    }

    public void find(T x) {
        Node tempstart;
        tempstart = start;
        while (tempstart!=null) {
            if(tempstart.getN()==x) {
                System.out.println("Element found");
                tempstart = tempstart.getNext();
            } else {
                tempstart = tempstart.getNext();
            }
        }
    }
    public void delete(T x) {
        Node previous=null;
        Node tempstart = start;
        while(tempstart!=null) {
        if(tempstart.getN()==x) {
            if(previous ==null) {
                previous = tempstart;
                tempstart = tempstart.getNext();
                start = tempstart;
                previous.setNext(null);
                previous = null;
            } else {
                tempstart = tempstart.getNext();
                previous.setNext(tempstart);
            }
        }else {
            previous = tempstart;
            tempstart = tempstart.getNext();
        }
        }
    }
    @Override
    public String toString() {
        Node tempNode = start;
        String str = "Values: ";
        while (tempNode!=null) {
            str = str + " " + tempNode.toString();
            tempNode = tempNode.getNext();
        }
        return str;
    }
}

Trial.java

public class Trial {
public static void main(String[] args) {
    String[] para = {"Hollo","this","is","me"};
    LinkedList<String> L1;
    L1 = new LinkedList<String>(para);
    System.out.println(L1);
}
  • 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-05T04:09:05+00:00Added an answer on June 5, 2026 at 4:09 am

    You should declare the start, end, and current fields in LinkedList< T > and the next field in Node< T > as type Node< T >, not Node. Don’t use raw types anywhere in the code, because they translate into Node< Object >.

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

Sidebar

Related Questions

I'm trying to make an app I'm designing more generic and implement the command
Designing forms has always been fun, but getting them to send email on the
When designing an distributed application in Java there seem to be a few technologies
I am designing an intranet application. This intranet is for a parent company which
Can I use a marker annotation on an enum when designing a generic interface?
I'm implementing an API using authentication based on this article: http://www.thebuzzmedia.com/designing-a-secure-rest-api-without-oauth-authentication/ And this related
Please post the points one should keep in mind while designing or coding for
I'm designing a generic survey engine and I've ran into some UI design related
I am designing a set of generic interfaces in order to clarify the construction
I'm designing an API (in Java) and expect to have users accessing the API

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.