18

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?

PNS
  • 19,295
  • 32
  • 96
  • 143
  • did you try to restart your pc? or re-install your IDE? or Cleaning up your project? – Kick Buttowski May 04 '14 at 23:57
  • I have tried many such workarounds, sort of uninstalling and reinstalling IntelliJ. – PNS May 04 '14 at 23:59
  • Is there any reason you use such an IDE? Why do not you use NetBeans or other famous IDE that have better supports? – Kick Buttowski May 05 '14 at 00:00
  • 6
    There are many reasons, but this is beside the point. After all, IntelliJ is a well-known IDE. :-) – PNS May 05 '14 at 00:02
  • Try rebuilding indexed info (no idea where to start from) or refresh project subtree in navigator. Even though it's strange for IDEA. I usually faced with such bugs in Eclipse. Maybe, you occasionally changed permissions for dir, IDE uses? – kirilloid May 05 '14 at 00:03
  • It can find the new classes and compile them, spotting any errors, so indexing does not seem to be the problem. – PNS May 05 '14 at 00:10
  • I switched back to 12.1 and it works as expected, so that will do for now. Maybe reinstalling a fresh download of IntelliJ will do the trick. – PNS May 05 '14 at 00:51
  • @PNS Does explicit code completion work after f.? Anyway it sounds as a bug in IDEA, please report it to http://youtrack.jetbrains.com/dashboard#newissue=yes, attaching some screenshots illustrating the issue and your log (Help | Show log). Thanks. – Peter Gromov May 05 '14 at 10:37
  • I would invalidate your caches first before reporting a bug. File->Invalidate Cache/Restart. I would bet this would fix your issue. – Michael May 05 '14 at 14:09
  • I have done that, too, and even disabled project auto-making, without any difference. I updated the question with a few more details of the behavior I am getting. Thanks. – PNS May 05 '14 at 14:22
  • did the failure occur after an auto update? Did you ever get resolution to this? does reinstalling the IDE help? – rogerdpack Jul 21 '14 at 18:01
  • 1
    Possible duplicate of [Intellisense in IntelliJ no longer working](https://stackoverflow.com/questions/22518529/intellisense-in-intellij-no-longer-working) – Loaf Jun 26 '17 at 13:23

16 Answers16

25

Make sure you mark all your Source directories as such in File -> Project Structure -> Modules.

Hubert
  • 485
  • 7
  • 14
19

Ensure that you are not in Power Save Mode while running IntelliJ (File [menu] -> Power Save Mode checked or not). If Power Save Mode is enabled, IntelliJ will not run background tasks, including code completion.

rogerdpack
  • 62,887
  • 36
  • 269
  • 388
Makoto
  • 104,088
  • 27
  • 192
  • 230
  • Then it will not provide auto-completion at all, not only for new classes, isn't it? – kirilloid May 05 '14 at 00:04
  • No; if power save mode is on at all, no code completion works. That's global across all files open in IDEA. – Makoto May 05 '14 at 00:05
  • Correct. In my case, Code Completion works as expected in existing classes, but not in any new one. The IDE is not in Power Save Mode anyway. :-) – PNS May 05 '14 at 00:05
  • Thank you. I had major problems with idea, maven and projects and this resolved all the problems. I had accidentally enabled power save mode and I had no idea that it was on. – t-my Nov 01 '14 at 11:48
14

For followers, one thing that helped me (auto complete only showed cast field instanceof etc.) was that I had opened a maven module that didn't link correctly to its children (it had a commented out submodules section), so IntelliJ just showed the maven java files as basically "text" files with a tiny "j" in their icon in the project pane. Fixing up the root maven pom.xml file to include the children dirs as modules and voila, they are treated as real java files again, woot!

rogerdpack
  • 62,887
  • 36
  • 269
  • 388
  • That may have been the case with my question, too, since the issue was fixed at some point, probably after linking a POM file to its parent. Thanks and +1. :-) – PNS Jul 22 '14 at 18:42
  • I had the same problem, and your suggestion inspired me to fix it. thanks! and +1. What I did was deleting the maven project from the Project section, and then added it again, and it worked afterwards. I think I accepted a menu suggesting a Maven configuration at some point. – evaldeslacasa Jan 13 '16 at 19:26
  • Thanks for helping me out, see tiny "j"s in the project pane too, and realise the problem – DiveInto Mar 10 '16 at 07:45
11

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

zoe jiang
  • 131
  • 1
  • 5
  • that was the solution for me. I had this small "J" visible on my Java Files. But why did this happen? – Try it Nov 16 '17 at 11:09
  • This might not be the preferred answer, but even for those who have no maven project and cannot fix their pom files it works fine. – BennyHilarious May 29 '19 at 08:31
6

I had this same problem and it was caused by me not having a folder marked as sources root.

Right click on your src directory and Mark Directory As > Sources Root.

hurlman
  • 366
  • 3
  • 6
6

It helped me to mark the src directory as the "Source Root". enter image description here

SilverC4t
  • 85
  • 1
  • 6
3

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.

İlker
  • 31
  • 1
3

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

miljon
  • 2,611
  • 1
  • 16
  • 19
2

There could be 2 reasons for your problem

  1. Either the the source folder is not properly configured in the your build java build path. If the source folder is not properly configured the autocomplete wont get the required class definitions and autocomplete would fail for your project.
  2. Restoring the default options in 'Windows > Preferences > Java > Editor > Content Assist > Advanced'
2

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

BludShot
  • 301
  • 1
  • 3
  • 16
2

The only thing that worked for me was killing IntelliJ (on Ubuntu) and starting it again.

2

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

Venkata Rahul S
  • 304
  • 2
  • 10
2

It was happening for me in a module that was not added in the parent project pom (they did it on purpose), that was the reason, I right clicked the pom.xml of the module that has the issue and clicked the

enter image description here

now the autocomplete came and in addition to that I can see the module as a separate project in the maven tab on the top right.

mcvkr
  • 3,209
  • 6
  • 38
  • 63
1

I was facing this issue while coding for eclipse-che client extension. Eclipse che modules are all of maven type. My client extension project was an independent module which can be compiled independent of the parent project. When I imported the same structure to Intellij my client-side extension project was not giving suggestions. After I include the client-extension project to the parent module (adding it to pom.xml) the suggestions started showing up.

Purushothaman
  • 417
  • 4
  • 6
1

Remove your package from the Settings>Editor>General>Auto Import>Java>Exclude from Import and Completion

I had run into this problem. None of the solutions from this post worked, but I was able to fix it because I accidentally put my project's package in the "Exclude from Import and Completion" settings.

change your intellij settings to include the package for completion

activedecay
  • 10,129
  • 5
  • 47
  • 71
1

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.
davejal
  • 6,009
  • 10
  • 39
  • 82
Sander
  • 61
  • 5