Debugging : My Experience
This week I was working on an open-source project - Drifty which is a File Downloader System built using Java. I was assigned to create a GUI (Graphical User Interface) version for Drifty.
Starting with the project
I created a Maven project in IntelliJ Idea IDE. The project (Drifty) did not have separate packages for Backend and CLI (Command Line Interface). The CLI was integrated with the Backend, so, adding a GUI would be a difficult task to do. Moreover, the GUI code can not be maintained well. So, I spent a great deal of time separating the Backend from the CLI. Finally, I was done. The process went well.
I created a separate package for the GUI version, installed all the dependencies and started the next process. I wrote some code to show a window with the required title, window size, etc. and ran the code. Hooray๐ฅณ! The code worked! ๐
I wrote some more lines of code to make the whole GUI application functional with the Backend which deals with downloading the file.
Bug enters...
I created TextFields
and TextArea
in the GUI app, that takes inputs from the user and displays outputs. I created a Progress Bar
to show the progress of the file download. Everything was alright but when I ran the code, it failedโ
Prism ES2 Error - nInitialize: glXChooseFBConfig failed
A runtime error has occurred. I got surprised when I could not find the solution to this error ANYWHEREโ
An idea struck my mind ๐ก!
IntelliJ has an option to Invalidate Cache and Restart. I clicked on that. The IDE restarted and fortunately, the Error has GONE! I excitedly ran the code again - The Build process went smoothly, but, after waiting for more than 5 minutes, the GUI window did NOT show upโI searched about the problem but did not find a solution to this exact problem.
What I did
As multiple threads were running when the program started, so, a printStackTrace()
method would always lead me to the Thread
class as the root of the error.
The start()
method is the main method for a JavaFX application, which is called from the main()
method when the application launches. So, I commented out method calls from down to the top, leaving the first method call which initializes the window. I ran the program again, but, the window still did not appear ๐ฐ.
Now, I straight away went into the method and repeated the above process. I ran the code once more, and fortunately, the window successfully appeared.
After carefully examining the method calls that I have made, I found the method mainWindow.sizeToScene()
was causing the problem. This method caused the window size to overflow from the screen, hence the window did not turn up. I quickly uncommented the whole program code and removed this (mainWindow.sizeToScene()
) method call. The program was successfully executed โ
and the window appeared ๐
!
Here is a link to the commit that I made to solve the issue.
Conclusion
I have tried out a new way to debug code without using standard debuggers that come packaged with IDEs. This helped me to find bugs in my code and fix them, when the debuggers packaged with IDEs, point to the wrong cause of the problem.
Here is what I learned and some of my recommendations -
Examine and understand from what point the actual application starts.
Comment out or remove method calls from the bottom part of the program to the top, leaving the main method call uncommented.
Run the code.
Check if the error occurs.
If yes, go inside the uncommented method and comment out all the lines leaving the main topmost lines crucial for the application to start.
Run and check for the error.
If the error still exists, repeat the process.
After some time, it will get fixed ultimately.
You may use websites like Stack Overflow to fix the problem with greater velocity.
Hello ๐, I'm Saptarshi Sarkar, a Software Developer and an open-source enthusiast.
Thank you for reading the article!
Feedback to improve this blog is appreciated and warmly welcomed. If you liked my blog, do share it.
Connect with me -
๐ All my links | Twitter | GitHub | LinkedIn
Subscribe to my newsletter
Read articles from Saptarshi Sarkar directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Saptarshi Sarkar
Saptarshi Sarkar
Saptarshi Sarkar is a software developer and an open-source enthusiast. He is familiar with technologies like Java and is currently learning DevOps. He loves contributing to Open-Source projects and also enjoys maintaining them.