1

I am trying to execute Java program via command line and getting classnotfound error.

  1 import java.util.LinkedList;
  2 public class LinkedList {
  3         private static LinkedList<String> list;
  4         public static void main(String args[]) {
  5                 list = new LinkedList<String>();
  6                 list.add("Linked");
  7                 list.add("lists");
  8                 list.add("are");
  9                 list.add("awesome.");
 10                 System.out.println(list.getLast());
 11                 System.out.println("YES");
 12         }
 13 }
~       

This is the error I am getting:

javac LinkedList.java 
LinkedList.java:1: LinkedList is already defined in this compilation unit
import java.util.LinkedList;
^
LinkedList.java:3: type LinkedList does not take parameters
    private static LinkedList<String> list;
                             ^
LinkedList.java:5: type LinkedList does not take parameters
        list = new LinkedList<String>();
                             ^
3 errors
1
  • 2
    What don't you understand about LinkedList is already defined in this compilation unit? Commented Nov 16, 2013 at 22:58

1 Answer 1

6

You have a name clash in your file.

Your custom class is named after a Java SE class it imports.

Rename your custom class to something other than LinkedList and it should go away.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.