Vaadin 14 CRUD Example: java.lang.NoClassDefFoundError: Could not initiali

Hello,

I have a pretty basic Crud example I’m working on that is getting the following error

I started with the spring starter project.zip for IntelliJ

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.crocker.projects.spring.MainView]
: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: Could not initialize class com.vaadin.flow.component.crud.CrudI18n
	at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:184)
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:87)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1295)
	... 74 more
Caused by: java.lang.NoClassDefFoundError: Could not initialize class com.vaadin.flow.component.crud.CrudI18n
	at com.vaadin.flow.component.crud.Crud.<init>(Crud.java:163)
	at com.vaadin.flow.component.crud.Crud.<init>(Crud.java:119)
	at com.crocker.projects.spring.MainView.<init>(MainView.java:39)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:172)

Here is my code:

EnterpriseDataProvider enterpriseDataProvider = new EnterpriseDataProvider(broadworks);

      Crud<Enterprise> enterpriseCrud = new Crud<>(Enterprise.class, createEnterpriseEditor());
      enterpriseCrud.setDataProvider(enterpriseDataProvider);
      enterpriseCrud.addSaveListener(e-> enterpriseDataProvider.persist(e.getItem()));
      enterpriseCrud.addDeleteListener(e-> enterpriseDataProvider.delete(e.getItem()));
      enterpriseCrud.addThemeVariants(CrudVariant.NO_BORDER);
      add(new Label("Hello World"));
      add(enterpriseCrud);
private CrudEditor<Enterprise> createEnterpriseEditor() {

        TextField enterpriseId = new TextField("Enterprise ID");
        TextField enterpriseName = new TextField("Enterprise Name");
        TextField supportEmail = new TextField("Support Email");
        TextField defaultDomain = new TextField("Default Domain");

        FormLayout form = new FormLayout(enterpriseId, enterpriseName, supportEmail);

        Binder<Enterprise> binder = new Binder<>(Enterprise.class);
        binder.bind(enterpriseId, Enterprise::getServiceProviderId, Enterprise::setServiceProviderId);
        binder.bind(enterpriseName, Enterprise::getServiceProviderName, Enterprise::setServiceProviderName);
        binder.bind(supportEmail, Enterprise::getSupportEmail, Enterprise::setSupportEmail);
        binder.bind(defaultDomain, Enterprise::getDefaultDomain, Enterprise::setDefaultDomain);

        return new BinderCrudEditor<>(binder, form);
    }

NoClassDefFoundError implies that there’s something missing from the classpath. In this case where com.vaadin.flow.component.crud.Crud tries to reference com.vaadin.flow.component.crud.CrudI18n, both files are expected to come from the same jar file which means that nothing is missing in that sense.

Instead, I suspect that you have a corrupted jar file in your local Maven cache. You could try removing all files from the /.m2/repository/com/vaadin/vaadin-crud-flow/ directory in your home directory.

There’s also a small possibility that this would be caused by accidentally having multiple versions of Vaadin Crud on the classpath, even though that is quite unlikely if you’re just using any of the starters.

Rebuilding the maven cache fixed the issue. Thanks