简体   繁体   English

IntelliJ - 无法解析符号“数组”

[英]IntelliJ - Cannot resolve the symbol 'Arrays'

  1. My code我的代码

我的代码

  1. SDK Level SDK级别

SDK & 等级设置

  1. SDK开发工具包

开发工具包

I am using我在用

  1. Windows 7 32bit OS Windows 7 32 位操作系统
  2. Java version "1.8.0_221" Java 版本“1.8.0_221”
  3. IntelliJ Idea 11.0.2 IntelliJ 理念 11.0.2

I am doing a basic program in Java.我正在用 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.我在Collections类中也遇到了同样的错误。

I tried in eclipse also, I am facing the same issue in Eclipse also.我也在 E​​clipse 中尝试过,我在 Eclipse 中也面临同样的问题。 I tried to specify libraries also.我也尝试指定库。 even not solved.甚至没有解决。 Might be something I have to do extra in settings.可能是我必须在设置中做一些额外的事情。

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. ...我怀疑编译器不喜欢new关键字。

This is a classical behaviour you will get in case there is no project SDK defined.这是在没有定义项目 SDK 的情况下您将获得的经典行为。 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).当没有项目 SDK 时,标准库提供的任何类都将不可用(因为那些由 SDK 提供)。

go to module settings->project->project SDK and select a proper JDK and language level.转到模块设置-> 项目-> 项目 SDK 并选择合适的 JDK 和语言级别。 You may after that change that per module if needed.如果需要,您可以在此之后更改每个模块。

It resolved.它解决了。 I installed 15.0.6 instead of IntelliJ Idea 11.0.2.我安装了 15.0.6 而不是 IntelliJ Idea 11.0.2。 Thank you very much once again for your suggestions.再次非常感谢您的建议。

Try :尝试 :

file -> manage ide settings -> restore default settings file -> manage ide settings -> restore default settings

It will be restored and good to go!它将被恢复,一切顺利!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM