java.lang.NoSuchMethodError when using an Addon

Hi there,

I’m right now trying to get the Addon “ContextMenu” to work with my maven vaadin project. After long and strenous trial and error and countless hours of googling I got my maven plugin to accept that the contextmenu addon was reachable online.

So after I added ContextMenu Version 4.2.1 to my project I thought I was finally set. But after implementing it and trying to start up the war it gives me a java.lang.NoSuchMethodError.

I did the following things:


private ContextMenu contextMenu;
private Table table = new Table();
//All kinds of other mumbo jumbo for the table

ContextMenuOpenedListener.TableListener tableOpenListener = new ContextMenuOpenedListener.TableListener() {
			
			@Override
			public void onContextMenuOpenFromRow(ContextMenuOpenedOnTableRowEvent event) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void onContextMenuOpenFromHeader(
					ContextMenuOpenedOnTableHeaderEvent event) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void onContextMenuOpenFromFooter(
					ContextMenuOpenedOnTableFooterEvent event) {
				// TODO Auto-generated method stub
				
			}
		};
		
		contextMenu = new ContextMenu();
		
		contextMenu.setAsTableContextMenu(table);
		
		contextMenu.addContextMenuTableListener(tableOpenListener);

My compiler found the import alright, for both the ContextMenu and the ContextMenuOpenedListener. But as soon as my server tries to acces either


		contextMenu.setAsTableContextMenu(table);
		
		contextMenu.addContextMenuTableListener(tableOpenListener);

it crashes with


HTTP ERROR 500

Problem accessing /. Reason:

    java.lang.NoSuchMethodError: org.vaadin.peter.contextmenu.ContextMenu.setAsTableContextMenu(Lcom/vaadin/ui/Table;)V

Caused by:

com.vaadin.server.ServiceException: java.lang.NoSuchMethodError: org.vaadin.peter.contextmenu.ContextMenu.setAsTableContextMenu(Lcom/vaadin/ui/Table;)V
	at com.vaadin.server.VaadinService.handleExceptionDuringRequest(VaadinService.java:1387)
	at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1341)
	at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:236)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
	at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:648)
	at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:455)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)
	at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:559)
	at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:232)
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1072)
	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:382)
	at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:194)
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1006)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
	at org.eclipse.jetty.server.Server.handle(Server.java:365)
	at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:485)
	at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:926)
	at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:988)
	at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:635)
	at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)
	at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
	at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:627)
	at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:51)
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
	at java.lang.Thread.run(Thread.java:722)

Any clues on how to fix this? If you need more information just tell me so, I’ll happily provide.

Is it possible that you might have two different versions of the add-on on your classpath? Or maybe you compile your application against one version and deploy with another.

I just looked into the classpath and it didn’t list any jars for the addon. Is that a problem? TBH I’m not that good with the whole java/linux setup so I may make newbie mistakes.

And I don’t know if the second question may be the case. I installed the jar on our local repositories (I think…) and added it with maven from our local repository. And maven accepted that just fine. I can’t get maven to communicate with the online vaadin repository, so I had to take this route. I had another thread for that problem: https://vaadin.com/forum#!/thread/3687644

Any ideas?

The add-on should be on the classpath of your application, and also on the classpath of the widgetset compiler (which also needs its sources on its classpath, but those should be in the same JAR).

If your classpath is missing the add-on, I would expect a ClassNotFoundException rather than a NoSuchMethodError, though. A NSME means that something has been compiled against a class that has the method but executed with a version of the same class that does not have the method.