Missing basic JavaDoc in Eclipse - java

Up to a few days ago, Eclipse was working fine in locating the javadoc for base classes such as Java.io.File. Recently, though, hovering over these classes only yields a message indicating that the source and javadoc are missing:
"Note: This element has no attached source and the Javadoc could not be found in the attached Javadoc."
I couldn't for the life of me locate the option that would let me reselect the location of the basic documentation. Does anyone know how to fix this?

I encountered this problem now a couple of times too. It's especially annoying if you have a lot of projects in your workspace and you don't want to set the javadoc locations for each project.
Referencing the online documentation works well indeed, and there is a way to do that globally for all Java libraries:
Go to: Window -> Preferences
Expand: Java -> Installed JREs
Select your default Java installation
Press ''Edit''
Select all the JRE system libraries
Press ''Javadoc Location...''
In the Javadoc location path put in the path to the online documentation. For Java 8 for example this is http://docs.oracle.com/javase/8/docs/api/. (If you press ''Validate...'' it will tell you if it is a valid javadoc location.)
Press ''OK'', then ''Finish'', then ''OK''
And here you have some images:
And your basic Java javadoc is ready to go.

Expand your JRE System library and find rt.jar (classes.jar for Mac OS X). Right click, and select 'Properties'.
You can then specify the Javadoc location (as well as the source location).

The best way to do it is
Go to Project > Properties > Java Build Path > Libraries and expand JRE System Library [your jre version] then, rt.jar. Select Source attachment, click Edit…. Select the source code file (External File…) and press OK.
Other ways to attach java source code is mentioned in this link
http://www.cavdar.net/2008/07/14/3-ways-of-jdk-source-code-attachment-in-eclipse/

Press ctrl+click (or command+click if you're on a Mac) on any method which doesn't have javadocs. For example, in this line:
System.out.println();
... assuming that no javadocs are available for println, control-clicking on println will open a new tab with a button labeled "Attach Source...". And that's it!

I had the same problem.
I uninstalled eclipse, removed all eclipse specific data from my user's home- and application data directory, uninstalled all Java JREs and JDKs but nothing helped.
The solution on my system was to change the protocol in the JavaDoc URL from HTTP to HTTPS
e.g. for JRE 7 i changed the URL from http://docs.oracle.com/javase/7/docs/api/ to https://docs.oracle.com/javase/7/docs/api/
(use the steps mentioned by Terry and replace the 'http' with 'https')

Related

Getting error message "Code Recommenders cannot download its model repository index"

My Eclipse works fine, but now, periodically a message box comes up saying
Code Recommenders cannot download its model repository index
What does this mean?
If you go to "Preferences"/"Code Recommenders"/"Models" you will see some Repository URL's listed. In my case it is http://download.eclipse.org/recommenders/models/photon/.
But when you call that URL you will get a 404 since the site has been archived in July 2019.
So this URL beeing invalid causes the Error. Since the URL is not available is seems save to silently ignore it, as beeing suggested in the error-dialog.
As beeing said in the Reviews on eclipse Marketplace the project is archived due to lack of comitting developers. And you may find an archived last version here: https://repo.eclipse.org/content/shadows/releases.unzip/org/eclipse/recommenders/stable/
As written in the other answer, Code Recommenders has been archived due to lack of active maintainers, see this forum post.
Therefore when the plugin tries to download the models it fails because the site does not exist anymore, and you will see the following error dialog:
While you could choose to ignore this download failure in the future, I am not sure if Code Recommenders actually does anything without its models (please correct me if I am wrong), so at this point you could also uninstall the plugin.
OR, you could download the models manually:
Download the archived data of Code Recommenders: https://archive.eclipse.org/archived_projects/recommenders.tgz (9.7 GB!)
Extract recommenders/downloads/models/photon
In Eclipse: Open "Window" > "Preferences" > "Code Recommenders" > "Models"
Remove the existing download.eclipse.org entry
Add a new entry with a file URI pointing to the folder you extracted earlier. Note that you have to percent escape the URI, e.g.
C:\Program Files\eclipse\recommenders becomes file:///C:/Program%20Files/eclipse/recommenders
Click the "Apply" (and Close) button
Note however, that since you downloaded the files locally and there is no active development, you won't get recommendations for new Java features.
I don't want any of you to have to download 10 gigabytes like in #Marcono1234's solution, so I re-uploaded version-specific code recommender models to mega.nz and shared them here.
Download the code recommenders
For Eclipse Juno users: https://mega.nz/file/tuRFGYQD#zB_mq6XwO7nupLqMDRWQRnnhD3-FAgT3ijtDQyGvjFE
For Eclipse Kelper users: https://mega.nz/file/NjxXFYyb#uwpP3zxESL02prgTimhDL35xPXMnDkbDwzrhJG1rcgc
For Eclipse Luna users: https://mega.nz/file/02g1DASB#3GSzaKtFSGsxhdnNx2aX47DoD22ZZ6aUu9eXTUvoxKg
For Eclipse Mars users:
https://mega.nz/file/xnQDTQLC#wmA0cfL_ChVHuQ9r0Mo_Js3ef_eDyg2yU6Z2_JTUPbE
For Eclipse Neon users: https://mega.nz/file/siBF1QYC#aVfX3-FS5sNfLmRqCPg6eUaovQPpEkMqIPWugv3E3qk
For Eclipse Oxygen users: https://mega.nz/file/9nAjUITQ#BpQ4HagdlrfZOelW8jqVgJWI-5QlA38JLCGpGoMbWpc
For Eclipse Photon users: https://mega.nz/file/oq5klCBR#vB8f0vmPH3gaYGwkw7U1SVThW5IxKMuvhBughN-sJi4
Extract it to any folders you want (in my case, c:\workspaces\eclipse\recommenders)
In Eclipse: Open "Window" > "Preferences" > "Code Recommenders" > "Models"
Remove the default entry
Add a file URL to the path you extracted your code recommender model. In my case, it's file://workspaces/eclipse/recommenders.
Click the "Apply" (and Close) button
Enjoy!

How can I view Java 10 Javadocs (in Eclipse)

Firstly, I do realize this question has been asked in many permutations all over stackoverflow. I searched quite a bit before posting, so please don't link to another SO question unless it answers my specific question and scenario.
I recently upgraded from Java 8 to 10. Now, however, I cannot view source or javadocs for any Java class or library. Makes coding a lot more cumbersome.
How can I attach the source and/or javadocs for Java 10, either OpenJDK's version of it and/or Oracle's? I've read other questions' answers about needing to download them separately, opening up the Installed JREs options section in Eclipse, and manually pointing Eclipse to the source/javadocs location.
I cannot find Java 10 javadocs for download, although I was able to find the Javadoc HTML page. I cannot find specific questions about Java 10, only Java 6/7/8/9.
I cannot find Java 10 javadocs for download
I think this one is what you're looking for:
http://www.oracle.com/technetwork/java/javase/documentation/jdk10-doc-downloads-4417029.html
Step 1: Window --> Preferences --> Java --> "Installed JREs"
Step 2: Select the jre and click edit.
Step 3: Select as shown in the screenshot and provide the source by selecting source attachment.
Step4: Click the external file and give the source for zip file "Src" as shown below. And click ok.
Step5: Provide java doc location https://docs.oracle.com/javase/10/docs/api/ as shown below.
Step6: Click Ok and Click apply and close and you are good to go.

Javadoc for jdk1.7.0_06 not working in eclipse

I'm not getting the javadoc (I guess it's called) popup in Eclipse which gives details about the Java/Android method I'm currently hovered over. For instance, if I type Log.d and hit CTRL+SPACE there is usually a popup which shows some info about the Log.d method. This isn't happening. Any ideas how to fix it? I recently upgraded to jdk1.7.0_06 and I think the Java docs got smoked somehow. I followed a few different threads on S.O. to try and fix it but still nothing.
I've downloaded jdk-7u6-apidocs.zip from oracle and tried loading it in Window > Preferences > Java > Installed JREs > [select jre] Edit > JavaDoc location but when I try to validate, a popup says: "Location might be invalid. Files 'package-list' and 'index.html' that are typically available at the root of the documentation created by the Javadoc tool have not been found"
So then, in the same dialog above, I ticked 'Javadoc URL' and entered "http://download.oracle.com/javase/7/docs/api/". It validates OK, but I still don't have documentation for Log.d and others.
So, I guess how do I get the documentation popup back, and is this a java issue or android SDK issue?
Instead of pointing to JRE, you can try to point to JDK. In that way source is also be linked
Nevermind. Follow alphaRiv's solution here: JavaDoc not working in Android project
My path was borked so pointed it to my android-sdk-linux/docs/reference directory and all's well.

Eclipse/Java code completion not working

I've downloaded, unzipped and setup Eclipse 3.4.2 with some plugins (noteable, EPIC, Clearcase, QuantumDB, MisterQ).
Now I find when I'm editing Java projects the code completion is not working. If I type String. and press ctrl+space a popup shows "No Default Proposals" and the status bar at the bottom shows "No completions available".
Any ideas?
Try restoring the default options in 'Windows > Preferences > Java > Editor > Content Assist > Advanced'
An example of the kind of data you see in this preference screen, however not necessarily what you currently have.
(From Vadim in this blog post " Content Assist Duplicates in Eclipse (Mylyn)":
if have duplicate Mylyn entries, uncheck the duplicate entries that do not contain "(Mylyn)" in their name)
The Eclipse help page defines the default list to restore:
Select the proposal kinds contained in the 'default' content assist list:
Other Java Proposals,
SWT Template Proposals,
Template Proposals,
Type Proposals
I'm adding an answer here in case someone else finds this on Google. Same symptoms; different problem. For me, the type caches had become corrupt.
From http://mschrag.blogspot.co.nz/2009/01/open-type-cant-find-your-class.html
Quit Eclipse
Go to workspace/.metadata/.plugins/org.eclipse.jdt.core
Remove *.index and savedIndexNames.txt
Restart Eclipse and search Ctrl+T for the offending type. The indexes will be rebuilt.
In case someone comes here and want to activate the autocomplete function, go to
Preferences -> Java -> Editor -> Content Assist.
Then in the Auto Activation section fill in Auto activation triggers for Java:
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ._
For those running Xfce + having IBus plugin activated, there might be keyboard shortcut conflict.
See more info on my blog: http://peter-butkovic.blogspot.de/2013/05/keyboard-shortcut-ctrlspace-caught-in.html
UPDATE:
as suggested by #nhahtdh's comment, adding the some more info to answer directly: IBus plugin in Xfce uses by default Ctrl+Space shortcut for keyboard layout switching. To change it, go to: Options and change it to whatever else you prefer.
Check the lib of your project. It may be that you have include two such jar files in which same class is available or say one class in code can be refrenced in two jar files. In such case also eclipse stops assisting code as it is totally confused.
Better way to check this is go to the file where assist is not working and comment all imports there, than add imports one by one and check at each import if code-assist is working or not.You can easily find the class with duplicate refrences.
Another solution which worked for me is to go to Java--> Appearence --> Type Filters and do disable all
None of these worked for me.
I was experiencing this issue in only once particular class. What finally worked for me was to delete the offending class and recreate it. Problem solved... mystery not so much!
If you have installed Google Toolbar for IE, may be you can face the same problem. Because, the toolbar capture the shortcut ctrl+Space.
I had this problem and like #Marc, only on a particular class. I discovered that I needed to designate Open With = Java Editor. As a Eclipse newbie I hadn't even realized that I was just using a plain text editor.
In the package explorer, right-click the file and chose "Open With".
I faced this problem, and spent hours trying to figure out the issue. tried to follow the steps mentioned in the different answers above, the solution I found is on the same lines as Mona suggested, but slightly different. Tried to add as a comment to Mona's answer but no option was available.
Issue with my eclipse was, classpath somehow got corrupted and all the jars and dependent projects were missing. after taking the latest .classpath from repository it worked fine.
Check that you did not filter out many options inside the Window > Preferences > Java > Appearance > Type Filters
Items in this list will not be appear in quick fix, be autocompleted, or appear in other various places like the Open Type dialog.
I also face this issue but it is resolved in different way.
Steps that I follow may be helpful for others.
Right click on project (the one you are working on)
Go to Properties > Java Build Path > JRE System Library
Click Edit... on the right
Choose the JRE 7
Once you have you configuration checked and completion is still not working:
make sure you have the right directory structure.
Do you see the right icon beside the file?:
It will tell you how the file will be treated by Eclipse:
I am posting this answer as I had that story with with Maven webapp artifact. By default Maven-WebApp does not create folder for sources and I put my Java into resources, wondering for 5 minutes what was going on... :)
Running STS on Java Spring Boot projects, here's what works for me :
Maybe this helps other people who come across the same issue.
My setup: old Gradle project (version Gradle 2.12) made by someone else, imported using the Gradle Import Wizard into STS (Eclipse Oxygen.2 (4.7.2)).
Code completion did not work either (and I still have hollow Js at the Java files), but at least I got the code completion to work by doing:
right click on the project folder > Properties > Gradle > Configure Workspace Settings > Java > Editor > Content Assist > Advanced
check "Java Proposals in upper window.
2x Apply & Close
I have run into this problem since upgrading to Eclipse 2019-09. Based on some of the suggestions above, this is what worked for me.
I had to go to Eclipse -> Preferences -> Java -> Editor -> Content Assist -> Advanced.
I found out that if I turn on any of the key binding proposals, Java Non-Type, Java, Java (Task-Focused) or Java Type proposal, then I was able to use auto complete. If I turned them all on, then not only did auto complete work, but I got duplicate methods listed. I am guessing, but I will probably used Java Type Proposals. Any clarification of what differs for these four types would be appreciated.
In my case, Intellisense had only disappeared in a few classes in one project. It turned out this was because of a missing library on the build path (although it worked previously).
So definitely check all the errors or problems in Eclipse and try to find if a library may be missing
For those who use the latest 3-19 eclipse build:
It just happened to me when upgrading from Oxygen to 3-19 eclipse version, so I assume the auto-complete feature does not migrated correctly during the upgrade process.
The only solution that worked for me was to create a new eclipse workspace, and import the project/s to it. It might take a few minutes, but it worth it - comparing to the time spent on other solutions...
I ran into this and it ended up being I was opening the file with the text editor and not the java editor.
For me the issue was a conflict between several versions of the same library. The Eclipse assist was using an older version than maven.
I had to go to the .m2 directory and delete the unwanted lib version + restart eclipse.
I experience problems on Eclipse Neon when editing a file which does not belong to the project directory. When I copy the same file to the project root directory, not even to the src directory, the completion starts working.
When the file is opened from a different directory, only completion for JRE works. That is for example: java. completes, but junit. does not.
Just in case anyone got to a desperate point where nothing works... It happened to us that the content assist somehow shrunk so no suggestion was shown, just the "Press Ctrl+Space for non-Java..." could be seen.
So, it was just a matter of dragging the corner of the content assist to enlarge the pop-up.
I know, embarrassing. Hope it helps.
Note: this was an Ubuntu server with Xfce4 using Eclipse Oxygen.
If you're experiencing this in an enum, or when initializing an array with anonymous classes, it's a known bug in Eclipse. See Eclipse content assist not working in enum constant parameter list.
We can change the settings as per our requirement.
Suppose we want to make java proposal as highest priority we need to do changes as shown below.
Windows > Preferences > Java > Editor > Content Assist > Advanced
Choose Java proposal and click on up button
For me in Sep 2021 it was an odd Eclipse bug. I had a multi-line string inside an annotation in my Class. This caused just that particular class to fail when trying to code complete (even though the class compiled just fine).

Specifying An Alternative JRE In Eclipse For An Application Launched From Eclipse

I am trying to specify an alternative jre (my default is 1.6 and i need to run with jdk 1.4.2) in Eclipse, for an application that i shall launch from eclipse. I am not sure if I am doing the right thing in the following code:
Path jreContainerPath = new Path("/usr/lib/jvm/j2sdk1.4.2_18/");
IVMInstall jre = JavaRuntime.getVMInstall(jreContainerPath);
workingCopy.setAttribute(IJavaLaunchConfigurationConstants. ATTR_JRE_CONTAINER_PATH, jre.getName());
However, the IVMInstall jre is null. I think I am not specifying the container path right, but I am not sure. And I must do it in the program. I would gladly appreciate any help on this. Thanks in advance.
Do you necessarily want to specify it in the program itself? Otherwise you could just go to the build path of the project and specify the alternative jre that you want to use. (right click on project -> java build path -> select jre -> click edit -> select alternate jre there)
getVMInstall returns JREContainerInitializer.resolveVM(jreContainerPath) which in turn calls getExecutionEnvironmentId().
It takes the second segment of the path as the id of the JVM (see getVMName() of the same JREContainerInitializer class)
May be that means the expected path is not the literal one, but one like '/jvm/j2sdk1.4.2_18', with 'j2sdk1.4.2_18' the name of one of the installed JREs of your eclipse configuration.
By analyzing the source classes some more, you should be able to figure out exactly what that method expects.

Categories