The List list = new List (id, name, genre); is given me an error saying «List» is abstract; cannot be instantiated. Not sure what this actually means, looked at a few different answered questions and nothing helped towards fixing this error. Any suggestions or solutions to this frustrating issue please feel free to help.
4 Answers 4
Your namespace is cluttered. In the main method, you have the following import statement;
This conflicts with the List class you are intending to use. Either remove the import, or name your List class something else. I recommend the latter, as a List is Java is a widely used interface.

You have imported this:
So when you try to create a new List instance, Java thinks you are trying to do new java.util.List() .
You can change the name of your class to avoid the conflict, or create your new instance defining the type explicitly:
To avoid problems and ugly code, I would just probably rename List to something else.

![]()
I’m trying:
MyObject o = new MyObject(new List(0));
Error:
java.util.List is abstract; cannot be instantiated
Do I have to make a List class? What is the problem and solution?
- 5658 Просмотров
- Метки: нет (добавить)
1. Re: java.util.List is abstract; cannot be instantiated
![]()
- Мне нравится Показать отметки «Мне нравится» (0) (0)
- Действия
2. Re: java.util.List is abstract; cannot be instantiated
![]()
List is an interface and you cannot instantiate interfaces.
You have to instantiate any of the concrete implementation of List —
ArrayList, Vector, LinkedList, etc. depending on your needs.
Something like this —
List names = new ArrayList();
You should use the interface type in your APIs, though to make them implementation independent.
Hope this helps.
- Мне нравится Показать отметки «Мне нравится» (0) (0)
- Действия
3. Re: java.util.List is abstract; cannot be instantiated
![]()
- Мне нравится Показать отметки «Мне нравится» (0) (0)
- Действия
4. Re: java.util.List is abstract; cannot be instantiated
![]()
The List is an interface and not a class. You can create objects of only classes. You cannot create objects of an interface or an abstract class.
The actual classes that implement the List interface are:
ArrayList, LinkedList, Vector and AbstractList (The last one is an abstract class and once again you cannot create instances of the AbstractList directly).
You should change your code line to one of the following: If it is just mere storing of objects that you are interested in, then go for the first one. creating an array list.
Vijay 🙂
- Мне нравится Показать отметки «Мне нравится» (0) (0)
- Действия
5. Re: java.util.List is abstract; cannot be instantiated
![]()
Thanks. Everyone who replied was correct.
The program has compiled okay. Now to deploy. 😐
Я пытаюсь использовать Handler в своем приложении. Но когда я создаю его так:
Я получаю следующую ошибку.
И когда я проверяю решения, он просит меня реализовать эти методы:
Я никогда раньше не использовал Handlers , и я использую его просто для вызова метода после некоторой задержки. Для этого я использовал:
Но это показывает ошибку:
Пожалуйста, помогите! Спасибо заранее.
Кажется, вы импортировали неправильный класс Handler
Измените его на
также, если вы используете
он даст ошибку, которая будет логически найдена как нечто подобное ошибке, поэтому либо используйте boolean handler = new Handler(). или просто использовать (new Handler()) <. `