Problem with calling an external class from AbstractHandler [message #1007358] |
Tue, 05 February 2013 10:44  |
Eclipse User |
|
|
|
I have an eclipse application with two classes:
import org.eclipse.ui.PlatformUI;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.SWT;
public class A extends org.eclipse.core.commands.AbstractHandler {
public Object execute(ExecutionEvent event) throws ExecutionException {
Listener buttonListener = new Listener() {
public void handleEvent(Event event) {
// from inside handleEvent, I am unable to make any call to class B
try {
System.err.pritnln("constructor scenario");
B myB = new B();
System.err.println("non-static scenario");
myB.nonStaticTest();
System.err.println("static scenario");
B.staticTest();
System.err.println("end of static scenario");
} catch (Exception e) {
System.err.println("caught an exception");
} finally {
System.err.println("finally");
}
}
};
Display display = PlatformUI.getWorkbench().getDisplay();
final Shell shell = new Shell(display, SWT.TITLE | SWT.MIN | SWT.CLOSE);
Button myButton = new Button(shell, SWT.PUSH);
myButton.addListener(SWT.Selection, buttonListener);
}
}
public class B {
public B() {
System.err.println("constructor");
}
public static void staticTest() {
System.err.println("static test");
}
public void nonStaticTest() {
System.err.println("non-static test");
}
}
When I run the code as shown above, I get the following output:
constructor scenario
finally
I then commented out the constructor and non-static scenarios and ran the code. The output became:
I don't understand why eclipse won't execute the code in class B. Class A and class B are located in different .java files in the same package. No exception is ever thrown and the first line in each method is a print statement.
Does anyone have any ideas about why I can't call class B? I did try running a Project....Clean to do a clean build in eclipse, but it didn't help.
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05384 seconds