Ellen Spertus
Ellen Spertus

Reputation: 6815

Javadoc in Eclipse failing to recognize packages

Thanks to this thread, I was able to get Javadoc links to work for my Android project within Eclipse on Windows. Specifically, "{@link android.widget.Toast}" is currently converted into a link to "http://d.android.com/reference/android/widget/Toast.html?is-external=true". I achieved this with the Javadoc option:

-linkoffline http://d.android.com/reference "file:/C:/Android/android-sdk-windows/docs/reference"

However, I get errors such as the following based on lines of my Java code (not the Javadoc comments):

C:\Users\Ellen\workspace\TestableToast\src\edu\mills\cs180\HelloAndroid.java:5: 
package android.view does not exist
import android.view.View;
                   ^ 
C:\Users\Ellen\workspace\TestableToast\src\edu\mills\cs180\HelloAndroid.java:6: 
package android.view.View does not exist 
import android.view.View.OnClickListener;
                        ^ 
C:\Users\Ellen\workspace\TestableToast\src\edu\mills\cs180\HelloAndroid.java:8: 
package android.widget does not exist
import android.widget.Toast;
                      ^ 
C:\Users\Ellen\workspace\TestableToast\src\edu\mills\cs180\HelloAndroid.java:10: 
cannot find symbol symbol: class Activity 
public class HelloAndroid extends Activity implements OnClickListener {
                                  ^

How can I fix these references?

Upvotes: 35

Views: 26348

Answers (8)

Pushpan
Pushpan

Reputation: 277

Project > generate Javadoc. Then, go to "Configure Javadoc arguments" and in VM options add "-bootclasspath /path/to/sdk/platforms/android-##/android.jar".

Worked for me :)

Upvotes: 7

Rohan Kandwal
Rohan Kandwal

Reputation: 9336

Thanks to answer provided by @PaŭloEbermann and @MarcelD-B, I was able to understand the root cause of the issue. However, since I am using Android Studio, I was bit confused as to where to add the argument. After some time, I was able to figure it out finally and I am putting it as an answer here for any other person who finds the similar issue.

For Android Studio, open Tools > Generate JavaDocs and add the following argument in Other command line arguments:-

-bootclasspath /path/to/sdk/platforms/android-##/android.jar

Note:- There's no need of adding any commas in the argument. However, if your SDK Path contains spaces then enclose the path in double quotes ("). eg- My SDK Path contains spaces so I used the argument-

-bootclasspath "F:\Android SDK\platforms\android-21\android.jar"

JavaDoc generation screen on Android Studio

Upvotes: 4

bocekm
bocekm

Reputation: 113

Windows Eclipse solution

Adding the android.jar to -classpath is indeed the correct approach. No ANT is necessary, though also viable. In case you want to be using Eclipse GUI (File->Export->Java->Javadoc) for generating Javadoc, there's no option to edit classpath in the dialog. You need to have the classpath set correctly beforehand. Two ways to achieve that:

  1. Edit manually the <path_to_your_project>/.classpath and add the following line:

    <classpathentry kind="lib" path="<path_to_your_android_skd>/platforms/android-<version>/android.jar"/>
    
  2. Right click on your project->Properties->Java Build Path->Libraries->Add External JARs->navigate to <path_to_your_android_skd>/platforms/android-<version>/android.jar

I found the Eclipse GUI approach better than using ANT hinted in some of the answers here because you get clickable references to your source code on any Javadoc warning/error in Console. When using ANT all you get in Console is printed output of the javadoc.exe command.

Upvotes: 2

Marcel D-B
Marcel D-B

Reputation: 945

This Works in Eclipse for me:

  1. Project --> generate Javadoc
  2. Go to "Configure Javadoc arguments."
  3. in VM options add "-bootclasspath /path/to/sdk/platforms/android-##/android.jar"

Upvotes: 83

Suman
Suman

Reputation: 11

This workaround in eclipse worked for me:

  1. Go to Project=>Properties and select "Java Build Path"
  2. Select "Order and Export" tab
  3. Move "android 2.x.x" and "Android Dependencies" to the top of the list

Upvotes: 1

zonky
zonky

Reputation: 1088

the answers above are quite good! include the classpath in your javadoc.xml and run is via ant-command or eclipse -> Run As -> Ant Build

BUT be sure that there are no whitespaces in the paths! I had this problems with C:/Program Files/... and it didn't work till i changed it to C:/Progra~1/...

also putting the path in quotes didn't work for me.

Upvotes: 3

Pēteris Caune
Pēteris Caune

Reputation: 45222

Adding -classpath parameter in the last screen of "Generate Javadoc..." wizard did not work for me: I got an error message saying that -classpath parameter can only be specified once.

Not really a solution, but a workaround:

  • In the "Generate Javadoc..." wizard, check the option "Save the settings of this Javadoc export as an Ant script". This generates javadoc.xml file in project directory
  • Edit javadoc.xml file and edit classpath attribute. Specifically, add "/path/to/sdk/platforms/android-##/android.jar" there and any other jars that you get warning messages about
  • Generate the javadoc with: ant -buildfile javadoc.xml. For convenience, I put this line in a javadoc.sh shell script.

Upvotes: 40

Paŭlo Ebermann
Paŭlo Ebermann

Reputation: 74800

You need to put the android classes in your javadoc classpath, too. For this, add the android jar file to the -classpath argument of javadoc (as you would do for your compiler).

I have no idea whether and where Eclipse gives you some configuration option for this, though.

Upvotes: 7

Related Questions