views:

696

answers:

3

Hi,

I have noticed that autocomplete is not working in some of java files in Eclipse. Also, the files where autocomplete is not working, display a hollow "J" as the icon for the Java file. The files where autocomplete is working, icon for java file is a filled "J"

I am wondering if someone can point out what went wrong all of suddent, why the change in icons and why autocomplete and syntax highlighting is turned-off in the files with a hollow "J" icon?

Thanks.

update

Basically, I was doing what VonC has suggested but Eclipse was not refreshing that it why I was thinking that VonC's suggestion isn't working, after doing a refresh, the problem resolved.

+9  A: 

Those with a hollow J aren't part of the build path of the project, so they can't participate in the normal build process and therefore auto-complete won't be enabled for these files (and other Java editor features!). You must add the folders with the Java files to be built to the build path using the 'source path' section of the project properties. This can be accessed by right clicking on a project in the project navigator / package explorer and going to Properties. See http://www.informit.com/articles/article.aspx?p=367962 for details.

Additionally, if the files aren't part of a Java project in the first place, you must create a project and move the files in, or put the files in an existing one. Again, make sure these file are under a source directory as described by that section of the project properties.

alt text

Chris Dennett
actually all source code in under one common directory, "src", most files are fine, only a couple of folders under "src" are containing java files with a hollow "J", their syntax highlighting is gone and autocomplete doesn't work.So how is this possible?
m_a_khan
Could you right click on one of those files, go to properties, and paste what you see on the initial info page as a comment? :)
Chris Dennett
Additionally, make sure that Build Automatically is enabled on the project menu, although I'm not sure this will make a difference. Also check your exclusion filters.
Chris Dennett
A screenshot of the package explorer might help to find the reason, too.
Arne
A: 

In this following picture, MyClass.java has a hollow J, because it is explicitly excluded from the sources to build:

alt text

Could you go to the properties of the project, "Java Build Path" Section, "Source" tab and see if some exclusion filter has been set ?
It is usual for instance to define:

**/Test*.java

to exclude at first building any unit-test class (when you have a large set of sources and do not want to be presented with Test classes during auto-completion, or do not want them considered during source searches).

VonC
For some reason, the Java Build Path was completely empty and that was causing the issue. I included the missing JAR files but now I need to include all packages back to the project. The only problem is that I get the error message "declared package is different than the expected package"
m_a_khan
@m_a_khan: make sure you select the right src directory, for if you don't, your packages won't match the directories. See http://www.coderanch.com/t/453731/IDEs-Version-Control-other-tools/Eclipse-error-Declared-package-does or http://forums.sun.com/thread.jspa?threadID=5376951 or http://www.eclipsezone.com/eclipse/forums/t73687.html
VonC
A: 

Since this question is highly ranked on Google, I will add a solution to fix general auto complete issue, not for 'hollow J' ones.

Try Preferences -> Content Assist -> Restore Default

bronze