简体   繁体   中英

Java can't find symbol in LinkedList class

I'm trying to implement a simple linked list using Java's LinkedList class but cannot seem to get the compiler to identify the LinkedList methods.

Some simple test code:

import java.util.*;
public class Test {
    public static void main(String[] args) {
        LinkedList ll = new LinkedList();
        ll.add(1);
  }
}

This results in the following error:

Test.java:6: error: cannot find symbol
    ll.add(1);
      ^
  symbol:   method add(int)
  location: variable ll of type LinkedList
1 error

I'm sure I'm making some simple mistake but I can't for the life of me seem figure it out on my own. Thanks for any help.

You've got your own class named LinkedList and it's confusing the compiler. Rename that class to anything else, as long as your new name doesn't clash with the core Java classes as yours currently does.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM