Problem with the sample

Hi folks,

It’s been a while since I’ve done Java and I’m trying to get back into this using the Vaadin framework. So, this may ultimately be a basic Java issue I’m having. But…

I’m trying to make the sample application work from chapter 2 of the Book of Vaadin. I just cut and pasted this into Eclipse. However, when running it I’m getting errors, which are:

Daemon Thread [“http-bio-8080”-exec-3]
(Suspended (The type new Button.ClickListener(){} must implement the inherited abstract method Button.ClickListener.buttonClick(Button.ClickEvent)))
Learning_vaadinApplication.() line: 18
NativeConstructorAccessorImpl.newInstance0(Constructor, Object) line: not available [native method]

NativeConstructorAccessorImpl.newInstance(Object[]) line: 39	
DelegatingConstructorAccessorImpl.newInstance(Object[]) line: 27	
Constructor<T>.newInstance(Object...) line: 513	
Class<T>.newInstance0() line: 355	
Class<T>.newInstance() line: 308	
ApplicationServlet.getNewApplication(HttpServletRequest) line: 82	
ApplicationServlet(AbstractApplicationServlet).createApplication(HttpServletRequest) line: 947	
ApplicationServlet(AbstractApplicationServlet).findApplicationInstance(HttpServletRequest, AbstractApplicationServlet$RequestType) line: 775	
ApplicationServlet(AbstractApplicationServlet).service(HttpServletRequest, HttpServletResponse) line: 438	
ApplicationServlet(HttpServlet).service(ServletRequest, ServletResponse) line: 722	
ApplicationFilterChain.internalDoFilter(ServletRequest, ServletResponse) line: 304	
ApplicationFilterChain.doFilter(ServletRequest, ServletResponse) line: 210	
StandardWrapperValve.invoke(Request, Response) line: 240	
StandardContextValve.invoke(Request, Response) line: 164	
NonLoginAuthenticator(AuthenticatorBase).invoke(Request, Response) line: 498	
StandardHostValve.invoke(Request, Response) line: 164	
ErrorReportValve.invoke(Request, Response) line: 100	
AccessLogValve.invoke(Request, Response) line: 562	
StandardEngineValve.invoke(Request, Response) line: 118	
CoyoteAdapter.service(Request, Response) line: 394	
Http11Processor.process(SocketWrapper<Socket>) line: 243	
Http11Protocol$Http11ConnectionHandler.process(SocketWrapper<Socket>, SocketStatus) line: 188	
Http11Protocol$Http11ConnectionHandler.process(SocketWrapper<Socket>) line: 166	
JIoEndpoint$SocketProcessor.run() line: 302	
ThreadPoolExecutor$Worker.runTask(Runnable) line: 886	
ThreadPoolExecutor$Worker.run() line: 908	
TaskThread(Thread).run() line: 680	

I’m running this in Tomcat 7. Any ideas what my problem might be? Thanks…

/mike

I just tried to run in tomcat7 and it all worked without a hitch:


public class VaadinApplication extends Application {
	@Override
	public void init() {
		final Window mainWindow = new Window("Vaadin Application");
		Label label = new Label("Hello Vaadin user");
		Button button = new Button("Text");
		button.addListener(new ClickListener() {
			@Override
			public void buttonClick(ClickEvent event) {
				mainWindow.showNotification("Clicked");
			}
		});
		mainWindow.addComponent(button);
		mainWindow.addComponent(label);
		setMainWindow(mainWindow);
	}

}

this is my code, a couple of this you can check:

  • Is ClickListener class of Button.ClickListener
  • Did you add the method buttonClick to the listener
  • Did you add @Override to the buttonClick method?

Well, I still get a bunch of errors inside the button part of this code, so I commented it out for now. But Tomcat still fails to bring up the page, giving me a 404 error instead.

So, I’m looking at the Tomcat log and it says this:

Mar 28, 2011 10:57:01 AM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: .:/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java
Mar 28, 2011 10:57:01 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]
{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:Learning Vaadin' did not find a matching property.
Mar 28, 2011 10:57:01 AM org.apache.coyote.AbstractProtocolHandler init
INFO: Initializing ProtocolHandler ["http-bio-8080"]

Mar 28, 2011 10:57:01 AM org.apache.coyote.AbstractProtocolHandler init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]

Mar 28, 2011 10:57:01 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 539 ms
Mar 28, 2011 10:57:01 AM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Mar 28, 2011 10:57:01 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.11
Mar 28, 2011 10:57:02 AM org.apache.catalina.loader.WebappClassLoader validateJarFile
INFO: validateJarFile(/Users/mike/Documents/Eclipse/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/Learning Vaadin/WEB-INF/lib/gwt-dev.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
Mar 28, 2011 10:57:02 AM org.apache.catalina.loader.WebappClassLoader validateJarFile
INFO: validateJarFile(/Users/mike/Documents/Eclipse/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/Learning Vaadin/WEB-INF/lib/gwt-user.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
Mar 28, 2011 10:57:06 AM org.apache.coyote.AbstractProtocolHandler start
INFO: Starting ProtocolHandler ["http-bio-8080"]

Mar 28, 2011 10:57:06 AM org.apache.coyote.AbstractProtocolHandler start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]

Mar 28, 2011 10:57:06 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 4122 ms

Wondering if not loading the GWT jar is a problem?

I guess another question is, why doesn’t this just work? I can understand if there are dependencies upon other components that I’ve not configured right (Eclipse, Tomcat, GWT, the JRE, or Vaadin itself), but assuming those are all in place, shouldn’t the sample apps just work?

/mike

Did you make any changes to tomcat? may try to reinstall a clean tomcat instance.

What version of java are you using?

Otherwise make a new project with the vaadin eclipse plugin and try again.

Okay, I figured it out. When running the application, I was doing so with the .java file selected in the project, so the URL it was trying to hit was:

http://localhost:8080/vaadinhello/WEB-INF/classes/com/example/vaadinhello/VaadinhelloApplication.java

instead of just:

http://localhost:8080/vaadinhello

Selecting the root of the project in Project Explorer makes it do the right thing when running it, and I get the expected output.

Sorry folks, just a noob mistake on my part, need to learn my Eclipse. Really appreciate the help, Joris, thanks.

/mike

Actually, I spoke too soon. I can get it working if all I do is display the label. As soon as I add the button stuff in, I get errors. This is true whether I use the stuff out of the Vaadin book, or from what Joris posted.

I get:

The method addListener(Button.ClickListener) in the type Button is not applicable for the arguments (new
ClickListener(){})
ClickListener cannot be resolved to a type
ClickEvent cannot be resolved to a type

Should I be importing anything besides com.vaadin.Application and com.vaadin.ui.*?

/mike

Import Button.ClickListener and Button.ClickEvent explicitly, or refer to them with the “Button.” prefix.

Eclipse does not always add imports of nested classes used in anonymous classes correctly unless you help it in one way or another.