jisu
jisu

Reputation: 481

Java ClassNotFound error when executing via command line

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

Upvotes: 1

Views: 804

Answers (1)

Mena
Mena

Reputation: 48404

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.

Upvotes: 6

Related Questions