Ruslan Slobodyanik
Ruslan Slobodyanik

Reputation: 53

Arrays cannot be resolved? Is this a Build path issue?

When I type Arrays.sort(arr) in Eclipse, I get this error Arrays cannot be resolved and when I left click the red underlined Arrays word I don't get import java.util.Arrays as expected. I installed JRE and JDK 1.8.0_20 and my Project build path is configured accordingly. What could be an issue?

Upvotes: 5

Views: 55037

Answers (4)

The OuterSpace
The OuterSpace

Reputation: 229

met this error on using Arrays.asList(1,2,3,4); import java.util.Arrays; and giving me red squiggly lines saying The import java.util.Arrays cannot be resolvedJava(268435846) but compiling and running seems ok. so i just went closing and running again my IDE. then everything went ok.

Upvotes: 0

Pradeep Singh
Pradeep Singh

Reputation: 1144

If you want to call Arrays.sort(....) method. You need to call it inside the main method( or any method) of your program. Not in class level. Please make sure that.

Upvotes: 1

Satish Chandra
Satish Chandra

Reputation: 31

I had the same issue in eclipse. I resolved it by changing the jdk compiler compliance level to 1.6 in the windows-->preferences-->java--->compiler.

Upvotes: 2

Óscar López
Óscar López

Reputation: 236114

Manually add the following line at the beginning of the .java file; if a package declaration is present add it right after it, otherwise add it at the start of the file (or to keep things organized, add it in alphabetic order with respect to other imports):

import java.util.Arrays;

Alternatively: type Ctrl+Shift+o to automatically import all the required dependencies.

Upvotes: 15

Related Questions