Eclipse/Java 代码完成不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/908489/
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-08-11 20:56:19  来源:igfitidea点击:

Eclipse/Java code completion not working

javaeclipseide

提问by Robert Brown

I've downloaded, unzipped and setup Eclipse 3.4.2 with some plugins (noteable, EPIC, Clearcase, QuantumDB, MisterQ).

我已经下载、解压并安装了 Eclipse 3.4.2 和一些插件(值得注意的是,EPIC、Clearcase、QuantumDB、MisterQ)。

Now I find when I'm editing Java projects the code completion is not working. If I type String.and press ctrl+spacea popup shows "No Default Proposals" and the status bar at the bottom shows "No completions available".

现在我发现当我编辑 Java 项目时,代码补全不起作用。如果我输入String.并按ctrl+space弹出窗口显示“无默认建议”,底部的状态栏显示“没有可用的完成”。

Any ideas?

有任何想法吗?

采纳答案by VonC

Try restoring the default optionsin 'Windows > Preferences > Java > Editor > Content Assist > Advanced'

尝试恢复Windows > Preferences > Java > Editor > Content Assist > Advanced”中的默认选项

An example of the kind of data you see in this preference screen, however not necessarily what you currently have.

您在此首选项屏幕中看到的数据类型示例,但不一定是您当前拥有的数据。

eclipse content assist setting

eclipse 内容辅助设置

(From Vadimin this blog post " Content Assist Duplicates in Eclipse (Mylyn)":
if have duplicate Mylyn entries, uncheck the duplicate entries that do not contain "(Mylyn)" in their name)

(来自这篇博文中的Vadim “Eclipse (Mylyn) 中的 Content Assist Duplicates”
如果有重复的 Mylyn 条目,请取消选中(Mylyn)名称中不包含“ ”的重复条目)

The Eclipse help pagedefines the default list to restore:

Eclipse帮助页面定义恢复默认列表:

Select the proposal kinds contained in the 'default' content assist list:

  • Other Java Proposals,
  • SWT Template Proposals,
  • Template Proposals,
  • Type Proposals

选择“默认”内容辅助列表中包含的提案种类:

  • 其他 Java 提案,
  • SWT 模板提案,
  • 模板提案,
  • 类型提案

回答by Shashi

If you have installed Google Toolbar for IE, may be you can face the same problem. Because, the toolbar capture the shortcut ctrl+Space.

如果您安装了 Google Toolbar for IE,可能会遇到同样的问题。因为,工具栏捕获了快捷方式 ctrl +Space

回答by Mona

Check the lib of your project. It may be that you have include two such jar files in which same class is available or say one class in code can be refrenced in two jar files. In such case also eclipse stops assisting code as it is totally confused.

检查您的项目的库。可能是您包含了两个这样的 jar 文件,其中相同的类可用,或者说代码中的一个类可以在两个 jar 文件中引用。在这种情况下,eclipse 也会停止辅助代码,因为它完全被混淆了。

Better way to check this is go to the file where assist is not working and comment all imports there, than add imports one by one and check at each import if code-assist is working or not.You can easily find the class with duplicate refrences.

检查这一点的更好方法是转到辅助不起作用的文件并在那里注释所有导入,而不是一一添加导入并检查每个导入是否代码辅助正常工作。您可以轻松找到具有重复引用的类.

回答by hoipolloi

I'm adding an answer here in case someone else finds this on Google. Same symptoms; different problem. For me, the type caches had become corrupt.

我在这里添加一个答案,以防其他人在谷歌上找到这个。相同的症状;不同的问题。对我来说,类型缓存已经损坏。

From http://mschrag.blogspot.co.nz/2009/01/open-type-cant-find-your-class.html

来自http://mschrag.blogspot.co.nz/2009/01/open-type-cant-find-your-class.html

  • Quit Eclipse
  • Go to workspace/.metadata/.plugins/org.eclipse.jdt.core
  • Remove *.index and savedIndexNames.txt
  • Restart Eclipse and search Ctrl+Tfor the offending type. The indexes will be rebuilt.
  • 退出 Eclipse
  • 转到 workspace/.metadata/.plugins/org.eclipse.jdt.core
  • 删除 *.index 和 savedIndexNames.txt
  • 重新启动 Eclipse 并搜索Ctrl+T以查找有问题的类型。索引将被重建。

回答by Peter Butkovic

For those running Xfce + having IBus plugin activated, there might be keyboard shortcut conflict.

对于那些运行 Xfce + 并激活 IBus 插件的用户,可能存在键盘快捷键冲突。

See more info on my blog: http://peter-butkovic.blogspot.de/2013/05/keyboard-shortcut-ctrlspace-caught-in.html

在我的博客上查看更多信息:http: //peter-butkovic.blogspot.de/2013/05/keyboard-shortcut-ctrlspace-caught-in.html

UPDATE:

更新

as suggested by @nhahtdh's comment, adding the some more info to answer directly: IBus plugin in Xfce uses by default Ctrl+Spaceshortcut for keyboard layout switching. To change it, go to: Options and change it to whatever else you prefer.

正如@nhahtdh 的评论所建议的那样,添加更多信息以直接回答:Xfce 中的 IBus 插件默认使用Ctrl+Space快捷键进行键盘布局切换。要更改它,请转到:选项并将其更改为您喜欢的任何其他内容。

回答by Nirmal Mangal

I faced this problem, and spent hours trying to figure out the issue. tried to follow the steps mentioned in the different answers above, the solution I found is on the same lines as Mona suggested, but slightly different. Tried to add as a comment to Mona's answer but no option was available. Issue with my eclipse was, classpath somehow got corrupted and all the jars and dependent projects were missing. after taking the latest .classpath from repository it worked fine.

我遇到了这个问题,并花了几个小时试图找出问题所在。尝试按照上面不同答案中提到的步骤进行操作,我找到的解决方案与 Mona 建议的在同一行,但略有不同。试图作为评论添加到 Mona 的答案,但没有可用的选项。我的日食的问题是,类路径不知何故被破坏,所有的 jars 和依赖项目都丢失了。从存储库中获取最新的 .classpath 后,它工作正常。

回答by Marc

None of these worked for me.

这些都不适合我。

I was experiencing this issue in only once particular class. What finally worked for me was to delete the offending class and recreate it. Problem solved... mystery not so much!

我只在一次特定的课程中遇到过这个问题。最终对我有用的是删除有问题的类并重新创建它。问题解决了...神秘不是那么多!

回答by Elroy Flynn

I had this problem and like @Marc, only on a particular class. I discovered that I needed to designate Open With = Java Editor. As a Eclipse newbie I hadn't even realized that I was just using a plain text editor.

我有这个问题,喜欢@Marc,只有在一个特定的班级。我发现我需要指定 Open With = Java Editor。作为 Eclipse 新手,我什至没有意识到我只是在使用纯文本编辑器。

In the package explorer, right-click the file and chose "Open With".

在包资源管理器中,右键单击该文件并选择“打开方式”。

回答by Aaron

Check that you did not filter out many options inside the Window > Preferences > Java > Appearance > Type Filters

检查您是否没有过滤掉 Window > Preferences > Java > Appearance > Type Filters 中的许多选项

Items in this list will not be appear in quick fix, be autocompleted, or appear in other various places like the Open Type dialog.

此列表中的项目不会出现在快速修复中、自动完成或出现在其他不同的地方,如“打开类型”对话框。

回答by asifaftab87

I also face this issue but it is resolved in different way. Steps that I follow may be helpful for others.

我也面临这个问题,但它以不同的方式解决。我遵循的步骤可能对其他人有帮助。

  1. Right click on project (the one you are working on)
  2. Go to Properties > Java Build Path > JRE System Library
  3. Click Edit... on the right
  4. Choose the JRE 7
  1. 右键单击项目(您正在处理的项目)
  2. 转到“属性”>“Java 构建路径”>“JRE 系统库”
  3. 点击右侧的编辑...
  4. 选择 JRE 7