IntelliJ Code Completion not working for new Java classes

PNS picture PNS · May 5, 2014 · Viewed 24.3k times · Source

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?

Answer

Hubert picture Hubert · Nov 6, 2015

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