Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ Code Completion not working for new Java classes

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?

like image 832
PNS Avatar asked May 04 '14 23:05

PNS


People also ask

Why Autocomplete is not working in IntelliJ?

I have tried the following according to this thread (Intellij IDEA CE 12 Android XML Code Completion not working): Go to File->Power Save Mode and disable it - it is off. Go to Preferences->Editor->Code Completion and check Autopopup code completion - this has been checked. Go to File->Invalidate Caches and restart.

How do I enable code completion?

Invoke basic completionPress Ctrl+Space or choose Code | Code Completion | Basic from the main menu. If necessary, press Ctrl+Space for the second time (or press Ctrl+Alt+Space ).

How do I open a new Java class in IntelliJ?

Create a new Java classIn the Project tool window ( Alt+1 ), right-click the node in which you want to create a new class and select New | Java Class. Alternatively, select the node, press Alt+Insert , and select Java Class.

How do I turn on auto suggestion in IntelliJ?

Press Ctrl+Alt+S to open the IDE settings and select Editor | General | Code Completion. To automatically display the suggestions list, select the Show suggestions as you type checkbox.


6 Answers

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

like image 152
Hubert Avatar answered Oct 19 '22 12:10

Hubert


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.

like image 30
Makoto Avatar answered Oct 19 '22 13:10

Makoto


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!

like image 39
rogerdpack Avatar answered Oct 19 '22 12:10

rogerdpack


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

like image 31
zoe jiang Avatar answered Oct 19 '22 11:10

zoe jiang


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.

like image 28
hurlman Avatar answered Oct 19 '22 11:10

hurlman


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

like image 23
SilverC4t Avatar answered Oct 19 '22 11:10

SilverC4t