繁体   English   中英

找不到符号Integer.valueOf(int)

[英]Cannot find symbol Integer.valueOf(int)

我有一个以前运行良好的旧项目,但今天打开了它,发现编译器告诉我'cannot find symbol Integer.valueOf(int)''cannot find symbol Integer.toHexString(int)'

似乎java.lang.Integer出问题了。 我使用的是IntelliJ,但如上所述编译失败,但是Eclipse可以正常工作。 此外,我将相同的代码粘贴到新的IntelliJ项目中,它也可以正常工作。

旧的IntelliJ项目的配置有什么问题吗? 有人遇到过这个问题吗?

示例代码如下:

public class ContainerTest {
    public static void main(String[] args) {
        @SuppressWarnings("unchecked")
        List numbers = new ArrayList(Arrays.asList(1, 2, 3)); // cannot find Integer.valueOf(int) here
        ListIterator listIterator = numbers.listIterator();

        while (listIterator.hasNext()) {
            System.out.println("index" + listIterator.nextIndex() + " : " +listIterator.next());
            listIterator.add(100);
        }

        System.out.println(numbers);
    }
}

public class BinaryFileTest {
    public static void main(String[] args) throws IOException {
        DataInputStream reader = null;

        try {
            String filename = "./target/classes/io/TreeInfo.class";
            reader = new DataInputStream(new FileInputStream(new File(filename)));
            int i = 0, k;

            while (reader.available() != 0 && i++ < 4) {
                System.out.println(Integer.toHexString(k = reader.read())); // here
                System.out.println(k);
            }

            reader.close();

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            reader.close();
        }
    }
}

要解决此问题,请确保在两个ide(eclipse和IntelliJ)中都使用相同的版本,这是很常见的。 在IntelliJ中,可以设置为在“ Project Settings > Project选择正确的Project SDK版本,以相同的方式在“ Project Settings > Modules选择项目,单击“ Dependencies选项卡,然后选择正确的Module SDK版本。

暂无
暂无

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

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