Is there any easy to follow tutorial for debugging Java / J2EE applications in eclipse?
A step by step guide on how to check for unchecked and checked exceptions?
I have been trying to find on the internet, but to no use.
To add a Java Exception Breakpoint: Select the "Breakpoints" view in the Debug perspective and click on the view toolbar button for exception breakpoints (or choose Run->Add Java Exception Brekakpoint). In the next dialog, type the name of the exception (camel case is support, simply type NPE if you want to catch NullPointerExceptions, you'll get a list matching items), select it from the list and press OK. C'est ca.
You can activate/deactivate this special breakpoint from the Breakpoints view like normal breakpoints.
More fun: right click on a breakpoint entry in the Breakpoints view and choose "Breakpoint Properties". There you can add extra conditions, like 'only break when myCustomString.equals("WTF")' or something else. But conditional breakpoints will slow down the application significantly, only activate them if you really need them.
The debugger in Eclipse will automatically suspend execution (and let you inspect variables/step/resume etc) if an uncaught exception is thrown.
Enter for instance the following program...
public class Test {
public void methodA() {
methodB("hello");
methodB(null);
}
public void methodB(String s) {
System.out.println(s.substring(2));
}
public static void main(String[] args) {
new Test().methodA();
}
}
... and click the little "bug"-icon or choose Run -> Debug As -> Java Application
A few useful tutorials
Debugging a Java Program with Eclipse
Java Debugging with Eclipse - Tutorial
Related
I am developing plugin for eclipse. It will run my clang tool. In clang tool i am writing simple pass to check that every case and default statement must have the break statement.
I am running my clang tool using process builder.
I am using job API to run my tool and Display class to print the error.
when i run my plugin i am facing some issue.
Let say i commented my break statement of one of the case or default statement , it should print error in console that every case and default statement must have the break statement.
it is printing error after i type something else or some space or trying to uncomment after my comment .
similarly when i do uncomment , it should not print the error , but it is printing , but again when i type something or some space or trying to comment , error disappear.
following is the link of my code
https://github.com/sunilsarode/eclipse_plugin/blob/master/ccchecker/src/ccchecker/handlers/SampleHandler.java
following image show the first case not printing error on my eclipse console on which i am developing a plugin .
and this shows that second case printing error on my eclipse console on which i am developing a plugin .
any help in this ?
EDIT:
I want my plugin-in to output something on console view (not on development console ) or some dot kind of thing on the gutter of the text editor and when i click or hover on that dot , i want to show some popup with error message.
I tried to print message on console view by crating console using this link https://wiki.eclipse.org/FAQ_How_do_I_write_to_the_console_from_a_plug-in%3F
it works , but new problem is , i lost focus from text editor to console that i have created and because of this i am unable to test the problem i mentioned in question.
sorry too much i am expecting.
Following image show that text editor lost its focus to console view and the button you have mentioned is not there at console view but it is there at console of eclipse on which i am writing a code.
Following keypress method and addKeyListener is not working when i press the Ctrl+s. In order to get the save event we have to use the ICommandService with save command.
((StyledText) editor.getAdapter(Control.class)).addKeyListener(new KeyListener() {
#Override
public void keyPressed(KeyEvent keyEvent) {
if (((keyEvent.stateMask & SWT.CTRL) == SWT.CTRL) && (keyEvent.keyCode == 's')) {
// System.out.println("From Display I am the Key down !!" + keyEvent.keyCode);
Job job = new Job("My job") {
#Override
protected IStatus run(IProgressMonitor arg0) {
// TODO Auto-generated method stub
StringBuilder builder = runCCChecker(path);
syncWithUi(builder);
return Status.OK_STATUS;
}
};
job.setUser(true);
job.schedule();
}
}
#Override
public void keyReleased(KeyEvent arg0) {
}
});
In order to show the warning at each line I am using IMarker interface.
In order to run my tool only on current active file of eclipse editor on which I am firing save command , I am using IPartService service.
following is the link of my code
https://github.com/sunilsarode/eclipse_plugin/blob/master/ccchecker/src/ccchecker/handlers/SampleHandler.java
It is working fine. If anybody find any issue please let me know.
I'm new to GWT and I need to get a right click working. The doco I've read suggests that I need to override the onBrowserEvent() method. I'm just experimenting at this stage. the event is processed and my pop-up appears. However, as soon as I close the pop-up, the usual browser drop down menu appears (with options like "Bookmark this page" and such).
I'm using IceWeasel 24.5.0 (FireFox clone for Debian) and, obviously, Debian (wheezy).
Here's the relevant code:
public ActivityTextCell() {
super(BrowserEvents.MOUSEDOWN, BrowserEvents.MOUSEUP);
}
#Override
public void onBrowserEvent(
com.google.gwt.cell.client.Cell.Context context,
Element parent,
ActivityDTO value,
NativeEvent event,
ValueUpdater<ActivityDTO> valueUpdater) {
super.onBrowserEvent(context, parent, value, event, valueUpdater);
event.preventDefault();
event.stopPropagation();
if (event.getType().equals(BrowserEvents.MOUSEUP)) {
Window.alert("mouse up event");
}
else {
switch ( event.getButton()){
case NativeEvent.BUTTON_RIGHT:
Window.alert("right mouseclick");
break;
case NativeEvent.BUTTON_LEFT:
Window.alert("left mouseclick");
break;
case NativeEvent.BUTTON_MIDDLE:
default:
break; // Do nothing
}
}
The class ActivityTextCell extends AbstractCell.
So what am I missing? How do I stop the browser from reaticng to the mouse click?
Well it certainly wasn't a matter of a few minutes (as can be seen by the fact that it has taken me a week to get back to this), but I have a solution. I tried reversing the order of the the event.preventDefault() and super.onBrowserEvent() but it didn't really help.
I tried a little experiment on a normal web page. It turns out, that the MOUSEDOWN event doesn't do anything in that context and the usual browser selection menu appears on the MOUSEUP. So the if/else logic sort of fell by the wayside.
What did the trick is to include the following in the top level GUI class immediately after adding the main page:
RootLayoutPanel.get().addDomHandler(new ContextMenuHandler() {
#Override
public void onContextMenu(ContextMenuEvent event) {
event.preventDefault();
event.stopPropagation();
}
}, ContextMenuEvent.getType());
This has the additional benefit (for my purposes, at least) of preventing the Browser from reacting to a right click anywhere in the application view.
As an aside: The purpose of preventing the default action is to stop the Browser doing its own thing Stopping propagation is possibly not required, but I left it in anyway (propagation goes fro the node up to the root, not the other way around). The purpose of overridinging onBrowserEvent() is to enable your own application to handel that event. The use of super.onBrowserEvent() is to allow the event to be handled by your code in the first place. I've given the relevant reference in my previous comment. The book "GWT in Action" is well worth a read if you're likely to be doing a lot of GWT coding.
You call super.onBrowserEvent() which triggers the standard browser response.
You should move event.preventDefault() to the if part of your code, and super.onBrowserEvent() to the else part. You want one of them executed depending on a browser event, but not both.
I am working on eclipse form based editor. I have given support of handling of Undo Redo and dirty flag to my editor.Both of these feature working fine for single instances of plugin. Problem is coming when i open it with 2 or more files (2 or more instances of eclipse plugin). Now, undo redo starts working weird. They work only for instances that is opened at last.
for eg: Suppose my editor supports '.xeb' file. if i open test1.xeb and test2.xeb files one by one using with my editor. then undo redo only works for instances that is opened for test2.xeb file. If i switch back to other instances, then undo redo of first instance gets appear.
i have below entries in my editor's plugin.xml:
<plugin><extension
point="org.eclipse.ui.editors">
<editor
class="Testeditor"
default="true"
extensions="xeb"
icon="icons/sample.gif"
id="testeditor"
name="editor">
</editor>
</plugin>
i debugged the code and found that this weird behavior is happening due to handling of global action in wrong way.I used below code to set global action handler:
public void setUndoRedoActionHandlers() {
final IActionBars actionBars = getEditorSite().getActionBars();
actionBars.setGlobalActionHandler(ActionFactory.UNDO.getId(),
mUndoAction);
actionBars.setGlobalActionHandler(ActionFactory.REDO.getId(),
mRedoAction);
actionBars.updateActionBars();
}
i went through some links related to this issue. but couldn't understood the concept to implement this behavior.
http://wiki.eclipse.org/FAQ_How_do_I_find_out_what_view_or_editor_is_selected%3F
http://wiki.eclipse.org/FAQ_How_do_I_hook_into_global_actions,_such_as_Copy_and_Delete%3F
Can any one look into this issue. Thanks in advance.
only override the setFocus() method of MultiPageEditorPart in you editor class and call the appropriate method of setting the global action handler,like this way:
#Override
public void setFocus() {
switch (getActivePage()) {
case 0:
pageOne.setUndoRedoActionHandlers();
break;
case 1:
pageTwo.setUndoRedoActionHandlers();
break;
}
super.setFocus();
}
The standard behavior of the Eclipse workbench is to preserve the set of open files between invocations, and attempt to reopen those same files on restart. If any of the files is missing, then a placeholder editor appears showing an error message about the missing file. We'd like to change the behavior of our Eclipse RCP application to just silently skip any missing files instead.
We're already writing our own IApplication, WorkbenchAdvisor, etc; these classes get to inject various behaviors into the platform, but I haven't found a way to accomplish these through these classes. How could we implement the desired behavior?
The way I've handled this is actually in the editor being created: Override setInput to examine the IEditorInput being passed in for validity by calling editorInput.exists() (which, in the case of a FileEditorInput, checks to see if the file exists) or if you're using custom editor inputs, any other validation you need.
If the editorInput fails validation, then close the editor asynchronously (Eclipse doesn't like it when an editor closes before it finishes opening):
public void close () {
Display.getDefault().asyncExec(new Runnable () {
public void run () {
getSite().getPage().closeEditor(YourEditorClass.this, false);
}
});
}
An alternative way of handling this issue is to just disable reopening the editors on startup - see In Eclipse, how to close the open files(editors) when exiting without auto-load in next startup
I've tested deployment to Android Market already as a test, seems like everything is hooked up fine - but now getting a little deeper into java and need to figure out how to use the Eclipse IDE.
I'm having exceptions, but where can see the exception message?.. it's not showing up in my consoles , not even the java stack trace console while in debug mode?
URLConnection uconn = null;
try {
uconn = u.openConnection();
catch (IOException e) {
e.printStackTrace();
x = x + e.toString();
}
Where does this output, not seeing it in any of the consoles. How can I output to console?
System.out.println("-----------------hello");
I can open up the view variable windows, but see no variables there, how do I add them into that so I can see their values, are they only they only visible if I add a line breakpoint? btw, what's the function key to step to next breakpoint?
Android exceptions are usually
visible at LogCat view, it is
available at DDMS perspective or you
can add it through menu Window ->
Show View -> Other.. -> Android
You'd better use log feature if you need to output something for debugging
Log.i("some tag", "message"); The log message is then visible at the LogCat view.
You need to stop at a breakpoint to see current value of variable, otherwise that makes not sense. Function keys from F5 till F8 are used to manipulate the flow. Usually F8 will bring you to the next breakpoint.