Reputation: 3564
I am using
I am doing a basic program in Java. But I am getting a compilation error:
Cannot resolve the symbol 'Arrays'
My code is this:
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class EmployeesData {
public static List<Employee> getEmployees() {
return Arrays.asList(
new Employee(201, "Kumar", "MS", 20000),
new Employee(202, "Kiran", "Wells", 30000),
new Employee(201, "Kumar", "Wells", 40000),
new Employee(203, "Vishal", "MS", 25000),
new Employee(203, "Srikanth", "MS", 45000),
new Employee(204, "Vimal", "Wells", 50000));
}
public static List<Employee> getEmployees2() {
String a = null;
return Collections.singletonList(
new Employee(201, "Kumar", "MS", 20000),
new Employee(202, "Kiran", "Wells", 30000),
new Employee(201, "Kumar", "Wells", 40000),
new Employee(203, "Vishal", "MS", 25000),
new Employee(203, "Srikanth", "MS", 45000),
new Employee(204, "Vimal", "Wells", 50000));
}
}
I am getting the same error for Collections class also.
I tried in eclipse also, I am facing the same issue in Eclipse also. I tried to specify libraries also. even not solved. Might be something I have to do extra in settings.
Upvotes: 0
Views: 5832
Reputation: 1091
Try :
file
-> manage ide settings
-> restore default settings
It will be restored and good to go!
Upvotes: 0
Reputation: 3564
It resolved. I installed 15.0.6 instead of IntelliJ Idea 11.0.2. Thank you very much once again for your suggestions.
Upvotes: 0
Reputation: 5663
This is a classical behaviour you will get in case there is no project SDK defined. When there is no project SDK none of the classes provided by the standard libraries will be available (as those are provided by the SDK).
go to module settings->project->project SDK and select a proper JDK and language level. You may after that change that per module if needed.
Upvotes: 1
Reputation: 125
The following works...
public static List<Employee> getEmployees() {
Employee[] e = {new Employee(201, "Kumar", "MS", 20000),
new Employee(202, "Kiran", "Wells", 30000),
new Employee(201, "Kumar", "Wells", 40000),
new Employee(203, "Vishal", "MS", 25000),
new Employee(203, "Srikanth", "MS", 45000),
new Employee(204, "Vimal", "Wells", 50000)};
return Arrays.asList(e);
}
...I suspect the new keyword is not liked by the compiler.
Upvotes: 1