Hi,
what's the error here??
public class countries {
public static void main(String[] args) {
List lands = new ArrayList();
lands.add("germany");
lands.add("austria");
lands.add("poland");
lands.add("luxomburg");
lands.add("switzerland");
System.out.println(lands.toString());
}
}
----------------------------------------------------------------------------------
Compilation Errors Detected
File: USER_173476/source/countries.java
Line: 4
cannot find symbol
symbol: class List
location: class countries
File: USER_173476/source/countries.java
Line: 4
cannot find symbol
symbol: class ArrayList
location: class countries
List lands = new ArrayList();
-
- Posts: 63
- Joined: Sun Jan 07, 2018 6:30 pm
Re: List lands = new ArrayList();
Hi!
You need to import List and ArrayList classes
You need to import List and ArrayList classes
Code: Select all
import java.util.List;
import java.util.ArrayList;
public class countries {
public static void main(String[] args) {
List<String> lands = new ArrayList<String>();
lands.add("germany");
lands.add("austria");
lands.add("poland");
lands.add("luxomburg");
lands.add("switzerland");
System.out.println(lands.toString());
}
}
-
- Posts: 2
- Joined: Sun Jun 17, 2018 11:40 am
Re: List lands = new ArrayList();
thank you very much, i did it.
-
- Posts: 1
- Joined: Tue Apr 28, 2020 1:38 pm
- Location: Estacada, OR, US
Re: List lands = new ArrayList();
I also had the same problem and copied the above code to my project after erasing all of my code. It gives an error:
Error: Could not find or load main class domain.HelloWorld
When I change the public class to "Hello World," I get a compilation error that says
USER_276191/source/domain/countries.java
Line: 5
class HelloWorld is public, should be declared in a file named HelloWorld.java
Does anyone know what the problem is?
Error: Could not find or load main class domain.HelloWorld
When I change the public class to "Hello World," I get a compilation error that says
USER_276191/source/domain/countries.java
Line: 5
class HelloWorld is public, should be declared in a file named HelloWorld.java
Does anyone know what the problem is?
Re: List lands = new ArrayList();
When your code is compiled, the compiler needs to work out what each and every identifier in your code means. As the compiler is going through the code it will find something and know what to do with it or not. Cannot find symbol error relates to the identifiers and means that Java cannot figure out what the "symbol" means.
You need to add import declarations on class file header.
ArrayList is member of java.util package.
And, remember that Java is a case sensitive language. ArrayList is different from Arraylist
You need to add import declarations on class file header.
ArrayList is member of java.util package.
And, remember that Java is a case sensitive language. ArrayList is different from Arraylist