java 为什么 IntelliJ IDEA 会为 System.out.println 给出“表达式语句不是赋值或调用”错误?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16260456/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 22:26:04  来源:igfitidea点击:

Why would IntelliJ IDEA give an 'Expression statement is not an assignment or call' error for System.out.println?

javastringintellij-idea

提问by nihilon

Here is the code:

这是代码:

public class TryStuffOutHere
{
    public static void main(String[] args)
        {
            System.out.println("Set the customer's name: ");
        }

}

When I type this, IntelliJ IDEA stops highlighting the string "Set the customer's name: " in all one color like it does for other string literals, and puts the red squiggly line between the words and displays "Expression statement is not an assignment or call." But, if I change the line to:

当我输入这个时,IntelliJ IDEA 停止高亮显示字符串“Set the customer's name:”,就像它为其他字符串文字所做的那样,并在单词之间放置红色波浪线并显示“Expression statement is not an assignment or call .” 但是,如果我将行更改为:

System.out.print("Set the customer's name: ");

The string again looks like a normal string assignment (all one color, no inspection flagging).

该字符串再次看起来像正常的字符串分配(所有一种颜色,没有检查标记)。

Even declaring the string separately and outputting the variable still produces the issue.

即使单独声明字符串并输出变量仍然会产生问题。

I've attached three images illustrating what I am talking about. Does anyone have any ideas about what is going on?Apparently, I am not allowed to post images yet. If you want/need screenshots, let me know. I'd be glad to sent them your way.

我附上了三张图片来说明我在说什么。有没有人对正在发生的事情有任何想法?显然,我还不允许发布图片。如果您想要/需要屏幕截图,请告诉我。我很乐意按照你的方式寄给他们。

UPDATE (April 28th, 2013): Well, I now have enough points to add screenshots. So, here they are:

更新(2013 年 4 月 28 日):好吧,我现在有足够的积分来添加屏幕截图。所以,他们在这里:

Image 1
enter image description here

图 1
在此处输入图片说明

Image 2
enter image description here

图 2
在此处输入图片说明

Image 3
enter image description here

图 3
在此处输入图片说明

Image 4
enter image description here

图 4
在此处输入图片说明

I've also discovered that the 10-12 second delay after invalidating the caches and restarting the IDE is because the IDE is still "updating the indices". After it does, the issue immediately pops up...sometimes. Further complicating it is that invalidating the caches and restarting has worked twice, until I quit and open the IDE again, at which point it resurfaces.

我还发现使缓存无效并重新启动 IDE 后 10-12 秒的延迟是因为 IDE 仍在“更新索引”。完成后,问题立即弹出......有时。更复杂的是,使缓存无效并重新启动已经工作了两次,直到我退出并再次打开 IDE,此时它重新出现。

回答by Andreas Wederbrand

It looks like it tries to interpret the code as some other language than java.

看起来它试图将代码解释为 java 之外的其他语言。

Do yo have some extra plugins active? Try to disable as many as possible just to make sure that none of them are interfering

你有一些额外的插件吗?尝试禁用尽可能多的功能,以确保它们都不会干扰

回答by Peter Lawrey

I would try deleting the caches and restarting. This sounds like a corrupt state in IntelliJ, I would also make sure you have the latest version 12.1

我会尝试删除缓存并重新启动。这听起来像是 IntelliJ 中的损坏状态,我还要确保您拥有最新版本 12.1