Android - failed to generate Javadoc with Android Studio Bumblebee - java

I'm trying to generate Javadoc using latest Android Studio via built in tool:
Tools=>Generate Javadoc...
Whatever I choose from a tool's parameters window there are a lot of errors thrown, regarding to the scope I choose it varies from 50 to 100 and all of them related to Android OS or Dalvik VM. Here are some of them:
error: package android.util does not exist
error: cannot find symbol ... symbol:class Context
error: package android.app does not exist
error: package dalvik.system does not exist
Target Android SDK is 31. Latest Java release installed. Did someone experienced the same issue? What am I doing wrong?
Thanks in advance.

First of all, sorry for my English (I use Google translation).
I just spent 5 days on this error and found a solution that works (for me...).
The latest versions of Android Studio (including Bumblebee) do not generate technical documentation correctly. Here is the procedure to generate it correctly.
In Android Studio, open the project.
First of all, identify all R imports and just replace R with * (example: import com.example.coah.*).
Start by following the classic javadoc generation process:
Tools > Generate JavaDoc
scope : Module
uncheck "Include JDK and library sources in -sourcepath"
Output directory : give the path to the folder that will receive the doc (create this folder beforehand outside the project folder)
Other command line arguments : -encoding utf8 -docencoding utf8 -charset utf8
Make OK. Normally documentation generation failed with "exit code 4".
In the output window, at the very top and on the very right (drag the horizontal scrollbar), click on
"#C:\Users\xxx\AppData\Local\Temp\javadoc_args" :
You get a preview of the contents of the file.
Copy the content and paste it into a text file.
Open the file.
It starts with "-classpath" followed by quotes and a list of file paths. The problem comes from the fact that in this list, the android.jar file is missing, which is normally found in:
C:\Users\xxx\AppData\Local\Android\Sdk\platforms\android-32\android.jar
Check the presence of this file in the user folder (replace xxx by the name of the user) : it may not be android-32 but android-30, or other. Once the right path has been found, it must be added to the classpath, in the first position, just after the quotes and without forgetting to add a ";" at the end to separate it from the next path. Please note that the "" must also be replaced by "/".
Save file.
Open a command window in admin mode and go to the project folder, src\app\main\java folder.
Still in the javadoc output window in Android Studio, copy the first complete command line (which generates the doc) and paste it into the command window, replacing just what is after # with the path to the file text that has just been created (which contains, among other things, the classpath).
It is possible that there are errors and warnings, but the doc is still generated.
Emds

Emds solution helped a lot over here, using it we can solve this problem more easily.
As they said here, main problem is android.jar file is not being included in classpath somehow. So to resolve this we can simply copy path of android.jar (with name too) and then generate a dependency in project for it.
To do this go to File -> Project Structure -> Dependencies
There click on + sign in "All Dependencies" section and select "Jar/AAR Dependency".
Then select "app" for module and in next screen enter android.jar path (path you copied before) and click OK.
Build gradle again and generate Javadoc. It should do the trick.

Related

How can I get stdlib.jar to work in IntelliJ IDEA?

I​ had used the IntelliJ IDEA installer provided in the booksite for Computer Science: An Interdisciplinary Approach and I had no problem to use the library. However, I noticed that installation had screwed my Git bash display settings, so I uninstalled everything.
Later, I installed the latest version of IntelliJ (2021.3.3), from the JetBrains website and apparently all the previous settings were overwritten, since I could no longer use the library. So, I downgraded back to the version provided in the booksite, however, I still can't use the Std library.
I've tried adding the versions of the library .jar files that I found:
On the Standard Libraries Princeton's webpage
On the Jar Download website
On this post from Stack Overflow
In the .jar file from the hello.zip file I found on this other Princeton webpage
Together and independently to the module and libraries, via IntelliJ IDEA, following the paths: "File > Project settings > Modules > + > JARs or directories" and "File > Project settings > Libraries > + > Java" , respectively, and choosing the corresponding directory/file, with no luck, since I've got the "cannot find symbol" error message:
Barnsley.java:16: error: cannot find symbol
StdDraw.setScale(-0.1, 1.1); // leave a 10% border
^
symbol: variable StdDraw
location: class Barnsley
For literally every single mention of the Std libraries in the code. I​ also tried editing the environment system variables and created a variable named "CLASSPATH" and linked it to the Stdlib.jar file and then, to the .lift folder that came with the hello.zip file, from the first week assignment. Again, no luck, because I kept getting the same error message.
Next up, I typed:
javac -cp stdlib.jar Barnsley.java
In the command line, and although that command itself didn't lead to any error message, when I tried to run the program, typing:
java -cp stdlib.jar Barnsley 10000
This error message showed up:
Error: Could not find or load main class Barnsley
Caused by: java.lang.ClassNotFoundException: Barnsley
I also vainly tried copying and pasting every .java file from Standard libraries webpage to the same directory where I keep the program files.
I know some (maybe lots of people) have asked the same or a similar question before, either here or in other forums, but I've been googling and looking for a solution for three days now and, as you can see, none of the reported solutions that I've found have been of help to me, that's why I decided to ask again, on my own.
Thank you for reading my post and/or for any help you can provide.
PS.: The Barnsley.java file in the error messages corresponds to the one provided in the 5th section of this webpage from the booksite.
[Edit - April 7th, 2022]:
I tried to follow #CrazyCoder advice, so I created a folder named "src", extracted all the files from the stdlib.jar file that came with the hello.zip file into src and also moved Barnsley.java to that folder. Next, Next, I tried to follow the instructions from the webpage he mentioned, as shown in the following screenshot:
And somehow, got the same error message when compiling:
I don't know what went wrong :C Any assistance would be highly appreciated.
[Edit - Later on April 7th, 2022]:
Something weird happened. I downloaded the file provided by #CrazyCorder and there was a warning about Amazon Corretto not being installed, that I decided to ignore.
I tried to run the program from the command line, with no luck, because I got the same error message as always. So, I noticed that there was no JDK assigned to the SDK slot in the Project structure, and I chose to use JDK 18 (following the path "File > Project structure > Project"), which is the one that I had previously installed on my computer, but that didn't really change a thing.
Lastly, I tried to run it from the IDE and that's when it finally worked!!! So, thank you, #CrazyCoder :D I still don't know why it doesn't work from the command line, though...
I also vainly tried copying and pasting every .java file from Standard libraries webpage to the same directory where I keep the program files.
This works just fine, you need to place all the .java files from the stdlib.jar into the sources root directory (marked in blue in the project view). Barnsley.java needs to be in the same directory.
The jar with .class files will not work in the dependencies/classpath as you cannot import classes from the default package in Java.
It was an extremely poor choice to keep the classes in the default package and it's the fault of the creators of this library/course. This simple oversight has caused major headaches over the years.

Just installed IntelliJ, and it cannot find or load my main class [duplicate]

I creating a program to work with databases and I am getting the following error when compiling in IntelliJ IDEA. Does anyone why this is happening and how I could solve it?
The error that you get occurs not on complilation, but when you try to run your application. It happens because Java was not able to find Table.class file inside db subdirectory of the project output directory (classpath).
It can happen for multiple reasons:
wrong main class selected in the run/debug configuration
Table.java is excluded from compilation (by accident or intentionally because it contained errors and you wanted to skip it while working on other code)
class not compiled because Build step is excluded from from Before launch steps in the Run/Debug configuration
project is misconfigured and there is no Source root defined for the directory containing db subdirectory
Table.java has incorrect package statement or is located/moved to a different package
project path contains a colon : on Mac/Linux or semicolon ; on Windows, it's used to separate the classpath and will render the classpath invalid. See this thread for details. Note that Finder on Mac may display colons in the path as slashes.
the jar may not execute if one of the dependent jars is digitally signed since the new artifact will include the partial signature of the dependency. See this answer for more details.
In project structure make sure you have the right Java version for compile.
there is a known bug that sometimes a Java project created from the Command Line template doesn't work because .idea/modules.xml file references invalid module file named untitled104.iml. Fix the module name manually or create a project from scratch and don't use a template.
on Windows "Beta: Use Unicode UTF-8 for worldwide language support" Region Setting is enabled. See IDEA-247837 for more details and workarounds.
When IntelliJ IDEA is configured to store module dependencies in Eclipse format source root configuration is lost due to a known bug. Configure the module to use IntelliJ IDEA format dependencies as a workaround.
In a properly configured project and with the correct run/debug configuration everything works just fine:
the jar may not execute if one of the dependent jars is digitally signed since the new artifact will include the partial signature of the dependency. See this answer for more details.
I must again emphasis the point CrazyCoder has here.
The (Oracle) JVM used to throw a SecurityException when you tried to run a Jar-File containing broken signatures. This made sense from a "What's wrong"-Point of view.
That is no longer the case. They are indeed throwing ClassNotFoundExceptions now - even if the class is right there in the file (no matter if it is in the default package/toplevel or way down in a nested package structure).
Here's what worked for me:
I deleted .ide folder, .iml file. And all other auto generated files by intelliJ then restarted my ide and I was asked if I want to make my project run with maven that's it.
Obviously I said yes :)
This is a known bug in the IntelliJ idea.
To fix this I just deleted the .iml and the .idea and restart the IDE.
It works for most of the cases
Edit: The files will be in the project directories.
In my case the default console app template works only if the project folder path does not contain underscore (_) in it. Underscore brings the error
Error: Could not find or load main class com.company.Main
Caused by: java.lang.ClassNotFoundException: com.company.Main
IntelliJ IDEA 2021.3.1 (Ultimate Edition)
Build #IU-213.6461.79, built on December 28, 2021
If you've tried everything else that others have suggested (deleting .idea folder, rebuild, etc) there's another place to check, especially if you've built an artifact jar. When you first build an artifact jar, IntelliJ adds a folder: META-INF to src directory. in it is a single file: MANIFEST.MF which has info pointing to the Main-Class for Java to find. If you've refactored your project package, unfortunately IntelliJ does not update this file with the new changes. My MANIFEST.MF has the following correct content:
Manifest-Version: 1.0
Main-Class: org.umoja4life.fatashibackend.MainKt
Where "org.umoja4life.fatashibackend" is the package name, and "MainKt" is IntelliJ's constructed name for a (pseudo) "Main Class" because fun main() has been defined in file "main.kt" in the package directory.
Newbies: btw, This will be confusing for you because there should be no actual "class Main {}" definition despite the error message stating there should be.
Before I discovered this file and after trying everyone else's suggestions, I found it quickest to just have IntelliJ start a project (with correct package name!), initialize it with a trivial main.kt having:
fun main() { println("hello world!") }
run and test that; then, I added back in all my other files, rebuilt, ran, and tested it. Apparently IntelliJ has some secret state information stored somewhere which doesn't get correctly updated if your refactor your package name for an already running project and jar.

Netbeans automatically cloning my jar based packages with their empty 'name equivalents'

I'm new at java programming so i just wanted to try something with ssh understand how it works and so i downloaded a java library which is mentioned in this Stack Overflow answer
. After a lot of failed attempts on importing this library into netbeans. I decided to simply put the files into my src folder. But Netbeans ide duplicating packages in the jar file with their 'name equivalent' empty packages and this prevents me to reach the classes in the packages because the IDE and the Code completion automatically sees the empty packs.I've search the network couldn't find anything about this problem.I 'm ready to share any log files if there are any of them .Here is my screenshot about this situation.
Screenshot Attachment
OS : Linux Mint Rosa
IDE : Netbeans 8.1 Linux version
Edit : I Already looked these topics
How to use .jar files in NetBeans? : At first i've tried this and in this solution netbeans not duplicating any empty packs but when i start to type somethin' like that import sshj.foo.*; Auto Complete can't find anything and also if i try to write the whole path to a specific class which is in an specific pack IDE gave me an error the pack that you're looking for is not exist.Secondly I've tried this
and got the same issue at first try.I can see the packs,classes and other stuff but still can't reach them in a random class which is imported project.
How can I include external jar on my Netbeans project : I've tried this and also this ran perfectly without errors as they said but when i try to reach classes still got the same problem so nothing changed.
How to add a JAR in NetBeans :
In this topic all of the replies explained types of libraries.That's not even related to my problem
How to use classes from .jar files? : I've tried to do explained in this reply also and I've transfered my jar file into a compiled .class extension file and this didn't solve my issue too.
I've just solved that problem with downloading part of the libraries from here.
All libraries need to contain three kind of jars ;
1 . Compiled files containing jar (with extension .class)
2 . Source files containing jar (with extension .java)
3 . Javadoc files containing jar (optional)
Open a project find libraries folder on ide right click and choose Add JAR/Folder specify the directory that contains the compiled files.After importing library hit right click over it and choose edit then specify the source files and javadoc files directories you are ready to roll.

Eclipse - Source not found

I know this question has been asked many times before, but none of the proposed solutions resolve my issue (or I'm not implementing them correctly).
I'm developing a plugin for OpenFire, and when I set a breakpoint in my plugin source Eclipse reports "Source not found". The JAR is built separate from the build of the OpenFire server. I've tried adding the JAR and specifying the source code directory, but no dice.
Here's the process I'm following: When I hit my breakpoint I'm clicking "Edit Source Lookup Path", clicking "Add", Java Library, User Library, click User Libraries, adding my library (tried both "Add JARs" and "Add External JARs"), and then specifying the folder that contains the source code. I've also tried:
Adding the source by selecting "File System Directory" instead of "Java Library"
Adding it by selecting "Workspace Folder"
In the Project Explorer, adding the source for my plugin to the Java Build Path
In the Project Explorer, adding my JAR as a Library and specifying the Source attachment
Thanks in advance for any suggestions.
Personally, I have no good experience in Eclipse JDT, when adding a source folder at the time it hits a break point. What I always prefer to do, is adding the source folder before debugging:
Select Project/Properties/Libraries
Select your library and "edit..." the source attachment
Select either the corresponding source folder or the zip/jar containing the package
After that, you should be able to open the source files in the virtual "Referenced Libraries" folder (directly below the "JRE System Library" folder inside the project), or when opening a reference to a linked class file from within the JDT editor. If you are able to access the source, then you should also be able to at least stop at the break point and see the corresponding source.
Else, you will have to check again, if the source folder is really valid: The source folder or source archive must contain the folder with the name of the root package of the library (e.g. the default Java "src.zip" inside the JDK folder also includes a corresponding "java" folder at its root). When in doubt, extract the archive and select the parent folder of the package you are interested in - sometimes source archives might be a mess or incompatible to JDT.
If this has been assured and it still doesn't work, chances are, that your linked source folder does not correspond to the compiled version of the library. Usually JDT will handle such inconsistencies fine, but if you try to open a source file, that is entirely different than the corresponding class file, you will encounter problems. In this case I would suggest either downloading the correct source version of the library, or recompiling the library from the source, if all else fails.
If opening a referenced source file from withing the JDT editor does work fine, and you are still unable to open the source files when a break point is entered during debugging, then most likely the class files are missing the line numbers of the corresponding source file. Again, you will have to recompile the library from the source in this case.
Finally, it is also possible to overwrite the default source lookup by specifying source folders or archives in the source tab of the launch configuration. But you should normally not need to do this, when your build path is configured correctly. From the Eclipse Help:
The Source tab defines the location of source files used to display source when debugging a Java application. By default, these settings are derived from the associated project's build path. You may override these settings here.
I had this very annoying problem for a long time but was finally able to solve it. In my case, a null pointer exception was being thrown somewhere in Java's Transformer.IsRuntimeCode(ProtectionDomain) function.
I didn't really need to know about this since the exception was being caught and handled, but eclipse would pause debugging every time this happened and tell me that the source wasn't available. As a result, I constantly had to keep pressing the button to continue code execution.
In order to prevent this from happening, I:
1. Clicked on the "Breakpoints" window at the bottom of the debugging
screen
2. Right clicked "NullPointerException"
3. Unchecked "Caught"
This prevented the debugger from pausing program flow during a caught NullPointerException.alt text
(source: SharpDetail.com)
And this another one as:
Eclipse doesn't crash. You're trying to step into a method, where eclipse doesn't know where to find the source (*.java) files and informs you about this. Here is how to tell eclipse where to look. Go to
Window->Preferences->Java->Installed JREs,select the JRE you are using and click Edit.
There, select all of the jar files in the list you see and and click Source Attachment....
In the window that shows up, select the fille src.zip, which is in your JDK folder (if you didn't uncheck it while installing the JDK). On the machine I'm on right now, that is
C:\Program Files\Java\jdk1.7.0_07\src.zip.
Save all your changes (possibly restart eclipse) and you won't see that error again.
Well it turns out the solution was anticlimactic. When Balder's recommendations did not work I tried debugging one of the stock OpenFire plugins and it worked just fine. I then created a new plugin from scratch, and by doing nothing other than adding the source to the project (Right-click on the project -> New -> Source Folder) it also worked just fine. I have no idea why Eclipse refuses to see the source for my original plugin, but I moved all my code and libraries over to the new plugin and debugging is working as expected.
Many times you put jar files in eclipse IDE as referenced libraries when binary version of application was downloaded. Usually done so by configuring the build path. But the binary does not have the source files. You have Binary version and source version of application.
One simple way is to download the source libraries that you also use maven to build the project.
Keep somehwere, may be inside your project workspace.
Now while seeing the class file (from eclipse, jar exploded) you may see the source not found, fine.... there is a button below and click on that, a new window opens and there select add external folder.
Reference it to the src folder of the source you downloaded(not the binary one) and kept somewhere as said above and it will show the class details from that.
I fixed this issue with doing the following:
Click at the menu Window - Preferences - Debug - Step Filtering And check all the packages like the following image.
(Step Filtering)
Then, debug again your project and thats it.
Best regards,
In my case, I had a breakpoint in the class declaration. I mean in the next line.
public class GenerateInterface implements JavaCall {
So, the debugger stopped in that line and showed the following message:
Source not found
I think unconsciously activate the breakpoint in that line.

Where to find javadoc

I am using eclipse for java. When I debug, 'source not found' came out, is it because of javadoc? Where can i find javadoc in my desktop?
It appears your debugger stepped into a library class, and Eclipse cannot find the source for said library class.
You must tell Eclipse where the source files are located.
This is not related to javadoc
When you debug and when you go to inside of a method to debug and if you call that method through a jar file you will get this "source not found". If you can use source codes instead of that jar you will not get that and it will direct you to required source line in that method.
Eclipse telling you that source is not found has nothing to do with javadoc, but with the actual java files.
Most probably you do not have your project configured has a java project with source folders configured. To configure your project source folders do the following:
Right click on your project's name in the navigator view
Select properties
Go to Java Build Path -> Source
Make sure all your source folders are there.
After making sure that all source folders are correctly configured, you should move on to your debug view, and while debugging:
Right click in the attached process
Select Edit Source Lookup
Make sure your project is in the list, otherwise add it.
It can also happen that Eclipse is trying to display you a source file which is not from your project but rather from some other jar you're using or from the actual Java Runtime.
If that's the case and you still want to debug that source too you have to download the source (the correct version you're using) and use the previous 3 steps in the debug view to add that source to your debug environment.

Categories