Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Plugin Development Environment (PDE) » Problem with calling an external class from AbstractHandler
Problem with calling an external class from AbstractHandler [message #1007358] Tue, 05 February 2013 15:44 Go to next message
birt user is currently offline birt userFriend
Messages: 26
Registered: January 2013
Junior Member
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:

static scenario
finally


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.
Re: Problem with calling an external class from AbstractHandler [message #1007451 is a reply to message #1007358] Tue, 05 February 2013 21:44 Go to previous messageGo to next message
birt user is currently offline birt userFriend
Messages: 26
Registered: January 2013
Junior Member
I actually made some progress on this issue.

In class B, I also have some other static methods which contain references to apache commons. When I removed those methods, the problem went away. I think that I need to figure out how to correctly add apache commons to my plugin's classpath.

I already tried right-clicking on my project, clicking 'Java Build Path' and adding it to the Libraries tab.

I also tried opening up my plugin.xml and adding it to the runtime classpath.
Re: Problem with calling an external class from AbstractHandler [message #1007662 is a reply to message #1007451] Wed, 06 February 2013 22:36 Go to previous messageGo to next message
birt user is currently offline birt userFriend
Messages: 26
Registered: January 2013
Junior Member
This issue is now resolved. My eclipse runtime classpath was missing a dependent jar. I haven't quite figured out why there wasn't a better error message, but the problem is now fixed.
Re: Problem with calling an external class from AbstractHandler [message #1007812 is a reply to message #1007662] Thu, 07 February 2013 15:08 Go to previous message
David Wegener is currently offline David WegenerFriend
Messages: 1445
Registered: July 2009
Senior Member
You were most likely receiving a NoClassDefFound error when calling the constructor on B. NoClassDefFound is not a subclass of Exception, so your catch block wasn't being invoked. If you change your catch to Throwable, then you would receive the message associated with the catch block.
Previous Topic:Update site build replacing qualifier
Next Topic:Custom toolchain problem: Info: Nothing to build for
Goto Forum:
  


Current Time: Fri Apr 19 21:12:41 GMT 2024

Powered by FUDForum. Page generated in 0.02775 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top