I use Netbeans for my Java IDE. I am building off a 3rd party API. I have built quite a bit on top of it. I try to leave good debugging messages around my code, but I am getting a very basic error message, then my program is closing. I get this Error - java.io.EOFException and then shortly after the program closes. I think it is just a system output printed line showing the error coming from the API.
Does anyone know of a technique in Netbeans of Java in general where I could identify where the error is coming from?
One can put a break point on the constructor for EOFException().
To do so:
From the menu select Window -> Debugging -> Breakpoints or (Alt+Shift+5)
In the Breakpoints window, right click for pop-up and choose New Breakpoint ...
Set Breakpoint Type to Method
Set classname to java.io.EOFException, for convenience click the All Methods for given class checkbox. (otherwise you would have to set different breakpoints for the different constructors)
Choose Run -> Debug Project (Ctrl+F5) to debug your program. It should stop when the EOFException is created.
Go to Window -> Debugging -> Call Stack to see where it was called from.
Related
I am running unit tests on java code using intelliJ and junit. The unit tests were working fine, and they still are . . . until I run in debug mode. Today, when I run in debug mode, all of a sudden, they start iterating through java files that are installed with java, I didn't write, and that I don't have permission for like the following:
This is part of the java code base that I don't have any control over and I didn't set any breakpoint here. Yet it pauses here and makes me click through it to get past it. I wouldn't care if this was only a couple of additional clicks to click through, but I have clicked like 50 times and it still keeps going through base java code that I have no control over and is not what is throwing any problem or issue.
I tried changing the settings for code coverage but that didn't seem to do anything. Is there any way to get junit to only stop at breakpoints that I, myself, specified? Any help here would be appreciated. I didn't see a similar question on Stack Overflow and the stuff on other sites is all about crafting the unit test itself.
So crazy coder (see above) was correct, but I thought I would add (after painfully trying every other alternative) that you have to go to: Run | View Breakpoints and then scroll all the way down on the left side panel (which you may not notice if you have tons of breakpoints like I did) and at the bottom there are breakpoints for Java exceptions. You need to click those OFF see below:
it's probably really easy but I still don't know how to do this.
Is it possible to run a method while a program in Java is running in debug-mode in Eclipse?
While debugging, open the "Display view" to run any code you want at the position you're currently at.
See:
https://help.eclipse.org/neon/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Freference%2Fviews%2Fdisplay%2Fref-display_view.htm
In debug mode, it will open a new perspective and it's going to show the workflow of your Main method, including all the methods invocations during it's execution, which variable's values has changed, everything that happen to the beginning until the end of your Main class code.
May you check this link, got a lot of usefull information.
From Javascript, I can simply write
debugger;
and when that line executes, it stops the code as if I had put a breakpoint there.
Is there an equivalent in Java? I need it to work in Eclipse specifically.
EDIT: can we take it as read that I am not an idiot and if placing a breakpoint with the IDE itself were an option, I would have already done so?
FURTHER EDIT: I had not thought it necessary to point out that since placing a breakpoint with IDE is not an option, any answer that revolves around placing a breakpoint with IDE is not likely to be helpful. In case everybody is dying of curiosity, the original code is not written in Java -- it's processed down to Java byte-code. As a result, Eclipse is confused enough it doesn't want to set breakpoints.
The JVM debugger, which Eclipse uses (mostly) under the covers, can set breakpoint at a line number in a method IF compiled with certain optional debugging info OR at method entry (always).
If your classes were compiled without debugging "lines" so the debugger can't set a line breakpoint, and you don't want to or can't recompile them, you can still set a method-entry breakpoint. In Package Explorer -- NOT an edit window for the source -- right-click the method name/signature and Toggle Method Breakpoint to on.
This can be combined with the comment by #ajp: add a method e.g. void [static] debugger(){} that doesn't do anything when you call it, but provides a convenient target where you can set a method breakpoint.
Warning: although it is possible to compile with partial debugging info, like debugging "vars" but not debugging "lines", generally people just use "debug on" or "debug off". If your classes are compiled without debugging "vars", the debugger will be much less useful.
I am probably going to get a few downvotes, but so be it...
If you open a source file in Eclipse and right-click on the left edge of the document view, you will get the popup menu illustrated in the image below.
As you can see, you have the option to toggle a breakpoint and also to turn off and on the line numbers. So, I am not sure what you mean by "My Eclipse is being operated in an environment where it cannot find line numbers to the source code". Unless you have some modified version of Eclipse that does not show this menu, I don't know what you mean by that. The option is there.
You wrote:
From Javascript, I can simply write
debugger;
and when that line executes, it stops the code as if I had put a breakpoint there.
And also:
can we take it as read that I am not an idiot and if placing a
breakpoint with the IDE itself were an option, I would have already
done so?
Option 1: The simple, "incorrect" answer is that there is no instruction in the Java language to make the program pause in a breakpoint nor there is an option like in languages like C++ to
make a debug build. So, your "ONLY" option is to execute a breakpoint from the IDE.
Option 2: The complicated, correct answer is that you can do what you want following these instructions: https://docs.oracle.com/javase/7/docs/technotes/tools/windows/jdb.html
In your case, I don't believe that you don't have the option to place a breakpoint with the IDE to debug your program; no matter how complex your program is. BUT, I am not here to debate that point. According to your post, you have to do option 2 laid out here.
I just used Android Studio to make an unmodified empty Android app. I'm trying to set an exception breakpoint.
The default exception breakpoint triggers repeatedly. So I added !(this instance of java.lang.ClassNotFoundException) as a condition, as suggested in this question.
However, I still get interrupted by my exception, this time with a modal dialog box:
How do I make an exception breakpoint that will stay silent until something exceptional happens?
Edited to clarify: I don't want to make a breakpoint for a specific exception, I want a general exception breakpoint that I can leave on at all times.
The key here is to use class filters in conjunction with configuration to break on all errors, setting them to very high-level namespaces.
Check the Class filters checkbox to enable class filtering. Then click the ... (elipsis) button to open the Class Filters dialog.
Specify class namespace patterns by clicking on the (Add Pattern) button. Enter:
com.myapp.* (replace this with the namespace prefix of your app)
java.*
android.*
Add any additional namespaces as necessary (e.g. 3rd party libraries)
Press OK
See here for full instructions.
Android Studio is essentially IntelliJ IDEA. You have got to use the + button in the top left corner of the Breakpoints screen to add a breakpoint for a specific exception.
See the following thread for details:
How to use Intellij Idea's exception breakpoints
I'm writing Java in eclipse and I'm just wondering if there's a shortcut or a way to open the class of the screen you are looking at when debugging an application.
So, I'm debugging a very large application, and at some point I open a dialog within the application, and I want to know which class in the Java project contains the code responsible for this dialog. Is there a shortcut to open this class in eclipse?
If you just want to go to a specific implementation of method or a class, ctrl + click will take you to the code (if it is not third party code, you will be able to see it)
If you are asking how to see the code getting executed in debug mode, use F6 key instead of F8.