IntelliJ Code Completion not working for new Java

2019-01-18 20:20发布

IntelliJ IDEA 13 has started exhibiting a very weird behavior in my local setup.

Namely, in any new Java class added to an existing project, Code Completion does not work. So, after declaring an object variable of any type in the new class and then typing the name of that variable, followed by the dot (.), no suggestions come up for any of the methods of the corresponding object.

For example, after declaring

File f = new File("/home");

typing f. does not bring up a list of all the methods in the File class, to select one from. As a matter of fact, when typing the dot (.), no suggestions appear and at the bottom left (in the status bar) of the IDE window, the message "Identifier expected. Identifier expected." is displayed. Sometimes, a long list of totally irrelevant methods from irrelevant components or libraries are proposed.

Strangely, Code Completion works as expected if the above declaration happens in any of the existing classes.

This behavior persists after many combinations of machine restart, IDE restart, project re-importing, closing/reopening, or rebuilding.

Any ideas?

14条回答
Anthone
2楼-- · 2019-01-18 20:55

Right click on project -> Add framework support -> Select Maven -> Click OK

查看更多
走好不送
3楼-- · 2019-01-18 20:56

I am using IntelliJ Ultimate 2017.1, and I encountered similar issue. Maven project, was trying to using selenium APIs, but the intellisense didn't pop up relative methods for me.

Here is the way I solved my issue:

Right click on your project src folder
Choose Mark Directory As Then select Sources Root

查看更多
时光不老,我们不散
4楼-- · 2019-01-18 20:58

This is not IntelliJ 13 but a more recent 2017.1.1 Community version. Adding this answer here so that others benefit from a cause that has its roots in the Gradle Configurations.

Now, in my case too the auto complete, Generate Override methods and other features were not working. What I figured out is that in my project settings, I had multiple configurations for the gradle modules. The moment I cleaned up the rest of the modules and retained the only one (apart from test) I needed for that project, all behaviors were back to normal.

Also in such cases of Gradle projects, remember to mark all your sourceSet root folders ad the Source folders.

Edit: If you do not want to create multiple configurations per sourceSet and you are importing a gradle module, on the import screen, you should also disable the Create a module for per sourceSet flag. Without this, I was having to remove the multiple modules after importing the module.Create module per sourceSet

查看更多
【Aperson】
5楼-- · 2019-01-18 21:02

Cut the folder .idea and the files *.iml in the root folder and paste somewhere else out of project. when you re-open the project , auto import will work again magically.

查看更多
来,给爷笑一个
6楼-- · 2019-01-18 21:02

I had similar problem, nothing in this topic helped.

So finally I made it work, I clear cache of IntelliJ and restart.

File > Invalidate Caches / Restart.. > Invalidate Cache and Restart (button)

enter image description here

查看更多
forever°为你锁心
7楼-- · 2019-01-18 21:04

I had a groovy project where somehow the jdk was not set as a dependency, so jdk classes would not autocomplete.

Fix:

  1. project structure
  2. modules
  3. (your module)
  4. tab Dependencies.
  5. In the field Module SDK, add a jdk.
查看更多
登录 后发表回答