List lands = new ArrayList();

Do you have a compilation error or a difficult problem to solve? Ask for help here
Post Reply
jundi1517@gmail.com
Posts: 2
Joined: Sun Jun 17, 2018 11:40 am

List lands = new ArrayList();

Post by jundi1517@gmail.com » Sun Jun 17, 2018 1:07 pm

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

dbremmen@gmail.com
Posts: 63
Joined: Sun Jan 07, 2018 6:30 pm

Re: List lands = new ArrayList();

Post by dbremmen@gmail.com » Sun Jun 17, 2018 6:20 pm

Hi!
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());

}
}

jundi1517@gmail.com
Posts: 2
Joined: Sun Jun 17, 2018 11:40 am

Re: List lands = new ArrayList();

Post by jundi1517@gmail.com » Sun Jun 17, 2018 7:44 pm

thank you very much, i did it.

shootforthestars212@gmail.com
Posts: 1
Joined: Tue Apr 28, 2020 1:38 pm
Location: Estacada, OR, US

Re: List lands = new ArrayList();

Post by shootforthestars212@gmail.com » Fri May 01, 2020 2:00 pm

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?

markaldo
Posts: 1
Joined: Fri Aug 21, 2020 5:44 am

Re: List lands = new ArrayList();

Post by markaldo » Fri Aug 21, 2020 5:46 am

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

Post Reply