Page 1 of 1

List lands = new ArrayList();

Posted: Sun Jun 17, 2018 1:07 pm
by jundi1517@gmail.com
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

Re: List lands = new ArrayList();

Posted: Sun Jun 17, 2018 6:20 pm
by dbremmen@gmail.com
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());

}
}

Re: List lands = new ArrayList();

Posted: Sun Jun 17, 2018 7:44 pm
by jundi1517@gmail.com
thank you very much, i did it.

Re: List lands = new ArrayList();

Posted: Fri May 01, 2020 2:00 pm
by shootforthestars212@gmail.com
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?

Re: List lands = new ArrayList();

Posted: Fri Aug 21, 2020 5:46 am
by markaldo
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