When using a list in Java, java.awt.List comes out and an error occurs

In Java programming, I used the list as usual, but sometimes I get the following error: list_error.png

This is because I'm using java.awt.List instead of java.util.List as the list.

What is java.awt.List?

It is a GUI part of Abstract Windows Toolkit used when creating GUI in Java, so-called ** list box **. Not a list of Java collections.

screen

listbox.png

Source

import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.List;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class AwtEx {

	AwtEx(){
		List awtList = new List();
		awtList.add("item01");
		awtList.add("item02");
		awtList.add("item03");
		
		Frame frame = new Frame();
		frame.add(awtList);
		frame.setSize(200, 200);
		frame.setLayout(new FlowLayout());
		frame.setVisible(true);
		
		frame.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent we) {
				frame.dispose();
			}
		});
	}
	
	public static void main(String[] args) {
		new AwtEx();
	}
}

How to respond

You can avoid using java.awt, but I think it will be easier if you set it in the development environment so that java.awt does not appear as shown in the link below.

How to make List 100 times easier to use in Eclipse

Recommended Posts

When using a list in Java, java.awt.List comes out and an error occurs
In Java 10, when you do gradle eclipse and JavaSE-1.10 comes out, ...
Collecting client information when an error occurs in a web application
After switching between Java 8 and 11 versions, an error occurs in confirmation
Let's create a TODO application in Java 12 Processing when a request comes in with an unused HttpMethod ・ Processing when an error occurs in the server
A reminder when an aapt.exe error occurs
What to do and how to install when an error occurs in DXRuby 1.4.7
Summary when trying to use Solr in Java and getting an error (Solr 6.x)
How to convert A to a and a to A using AND and OR in Java
I got an error when using nextInt, nextLine and substring.
Resolve CreateProcess error = 206 when running Java in a Windows environment
An error occurs when codedeploy-agent is installed in Ubuntu Server 20.04
Sort List in descending order in Java and generate a new List non-destructively
What to do when an UnsupportedCharsetException occurs in a lightweight JRE
Solution notes when an error occurs when downloading docker gpg using curl
[Java] Shallow copy and deep copy when converting an array to List
Cast an array of Strings to a List of Integers in Java
Avoid character code error in java when using VScode extension RUN-CODE
How to solve the unknown error when using slf4j in Java
When seeking multiple in a Java array
Resolved the error that occurred when trying to use Spark in an environment where Java 8 and Java 11 coexist.
Creating a project (and GitHub repository) using Java and Gradle in IntelliJ IDEA
Map without using an array in java
Bad habits pointed out in code reviews when Java was a beginner
Arrylist and linked list difference in java
An error occurred when executing a function from MyBatis with the OUT parameter set to CURSOR in PostgreSQL.
Solution that gives an error when trying to connect to DB (MySQL) in Java
Use without preparing an authentication file when using Firebase Admin SDK in Java
When you want to notify an error somewhere when using graphql-spring-boot in Spring Boot
Error 400 occurs when executing Query by specifying Japanese as a condition in SOQL
407 error when trying to access an HTTPS site in Java via an authenticated proxy
Be careful with requests and responses when using the Serverless Framework in Java
I get an error when adding a dependency
A memo when fumbling and developing using JavaFX
[Rails] Solution when migration error occurs in acts-as-taggable-on
A note when you want Tuple in Java
I have a question. I get an error when playing a video in Listview on android.
[Java] Precautions when referencing a reference type in a parent class and instantiating it in a child class
Customize the display when an error such as 404 Not Found occurs in Spring Boot
Create a portfolio app using Java and Spring Boot
Convert JSON and YAML in Java (using Jackson and SnakeYAML)
What to do when an error occurs in rails db: migrate ((StandardError: An error has occurred, this and all later migrations canceled :))
[Java] Sort the list using streams and lambda expressions
Write a class in Kotlin and call it in Java
What to do when a null byte error occurs
Quickly implement a singleton with an enum in Java
I tried using an extended for statement in Java
Differences in code when using the length system in Java
A program (Java) that outputs the sum of odd and even numbers in an array
I was trapped when I generated my own class equals and hashCode in Java using IDE
A story stuck with an error when building Vagrant + Virtulbox CentOS7.8 and creating a shared folder
What to do if a SAX Parser error occurs when using Liferay 7 / DXP on AWS
[java] sort in list
Error when using SnapKit
(Fixed) An error occurs when using Java 8 with the latest version (0.65.0) of Language Support for Java (TM) by Red Hat of VS Code.
A mistake made when displaying an image using Active Storage
When an error occurs even though validation is not set
I want to make a list with kotlin and java!
What happened in "Java 8 to Java 11" and how to build an environment
Easily get an integer from a system property in Java
Get error information using DefaultErrorAttributes and ErrorAttributeOptions in Spring Boot 2.3