Arrays cannot be resolved? Is this a Build path issue?
Asked Answered
R

4

5

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?

Ritualism answered 1/9, 2014 at 2:50 Comment(8)
Sorry couldn't attach screenshot due to not sufficient reputation points.Ritualism
Have you tried to import in manually (either type it or shift_ctrl_O)?Rafat
What version of eclipse?Randy
@ElliottFrisch Version: Helios Service Release 1 Build id: 20100917-0705Ritualism
@peeskillet Yes I have tried adding import java.util.Arrays and tried shift_ctrl_O -- it doesn't work It's interesting that if I have something like ArrayList array=new ArrayList(); then shift_ctrl_o imports java.util.ArrayList;Ritualism
@RuslanSlobodyanik The eclipse (Helios) from 2010 is not compatible with Java 8. I would suggest you upgrade eclipse to Luna, or downgrade Java.Randy
@ElliottFrisch That was the problem! I installed Eclipse Mars which is java jdk 1.8 compatible and the import for java.util.Arrays was recognized. Thank you.Ritualism
Same problem, different solution. We have a product that auto-downloads new versions of Java onto our local machines. Since our production boxes are still on Java 7, I found an old version on my hard drive and reinstalled that. Everything's happy again. When the corp servers go to Java 8, I will too. But for now I'm running again and that's a good thing.Quintal
F
15

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.

Fascia answered 1/9, 2014 at 3:22 Comment(3)
I have tried both.. neither work for me. Here's what coded looks like public class Main { /** * @param args */ public static void main(String[] args) { char[] arr="asda".toCharArray(); Arrays.sort(arr); } }Ritualism
@RuslanSlobodyanik delete all the imports in you class, and once again hit Ctrl+Shift+o . It might be possible that you somehow imported the wrong library. And make extra-sure that all the libraries that get imported are the right ones. This can't be a classpath problem, because java.util is a core library, included in the JDKDeckhand
These were all good tips thanks. Also I needed the right version of Eclipse, compatible with my version of jdk.Ritualism
I
2

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.

Infrequency answered 25/3, 2016 at 15:25 Comment(1)
This worked for me, though the issue was the compliance level of one of the dependency project, not of the main project.Temikatemp
A
1

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.

Anzus answered 27/6, 2017 at 7:3 Comment(0)
R
0

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.

Rand answered 29/2 at 22:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.