Navigator View Error

Hello everybody

I’ve trying a few hours to debug the Error, but i can’t find my mistake.
Can someone help me?

When I start the Project with one following line

        navigator.addView(ALLVIEW, AllView.class);
        //navigator.addView(APPLICATIONSVIEW, ApplicationsView.class);
        //navigator.addView(HARDWAREVIEW, HardwareView.class);

the Project is with no Error.

When I start the Project with two or all lines

        navigator.addView(ALLVIEW, AllView.class);
        navigator.addView(APPLICATIONSVIEW, ApplicationsView.class);
        navigator.addView(HARDWAREVIEW, HardwareView.class);

the Project is with Errors.

The Full Code:

import javax.servlet.annotation.WebServlet;

import com.vaadin.annotations.Theme;
import com.vaadin.annotations.VaadinServletConfiguration;
import com.vaadin.icons.VaadinIcons;
import com.vaadin.navigator.Navigator;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinServlet;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Button;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;

@Theme("mytheme")
public class MyUI extends UI {

    protected static final String ALLVIEW = "allView";
    protected static final String APPLICATIONSVIEW = "applicationsView";
    protected static final String HARDWAREVIEW = "hardwareView";

    @Override
    protected void init(VaadinRequest vaadinRequest) {

//         Add MainLayout
        final VerticalLayout layout = new VerticalLayout();
        layout.setDefaultComponentAlignment(Alignment.MIDDLE_CENTER);
        setContent(layout);

//         Add Topbar
        HorizontalLayout topbar = new HorizontalLayout();
        topbar.addStyleName("topbar");
        topbar.setSpacing(true);
        layout.addComponent(topbar);

//         Add Title
        Label title = new Label("Title");
        title.addStyleName("h1");
        topbar.addComponent(title);

        HorizontalLayout menuAndContent = new HorizontalLayout();
        menuAndContent.setSizeFull();
        layout.addComponent(menuAndContent);

//      Add Menu        
        VerticalLayout menu = new VerticalLayout();
        menu.setWidth("50%");
        menu.addStyleName("menu");
        menuAndContent.addComponent(menu);

//      Add Menunavigator
        Navigator navigator = new Navigator(UI.getCurrent(), this);
        Button products = new Button("Alle Produkte",new Button.ClickListener() {
            @Override
            public void buttonClick(Button.ClickEvent event) {
              navigator.navigateTo(ALLVIEW);
            }
        });
        products.setIcon(VaadinIcons.BARCODE);
        menu.addComponent(products);
        Button applications = new Button("Applikationen",new Button.ClickListener() {
            @Override
            public void buttonClick(Button.ClickEvent event) {
                navigator.navigateTo(APPLICATIONSVIEW);
            }
        });
        applications.setIcon(VaadinIcons.VAADIN_V);
        menu.addComponent(applications);
        Button hardware = new Button("Hardware",new Button.ClickListener() {
            @Override
            public void buttonClick(Button.ClickEvent event) {
                navigator.navigateTo(HARDWAREVIEW);
            }
        });
        hardware.setIcon(VaadinIcons.HARDDRIVE);
        menu.addComponent(hardware);

        navigator.addView(ALLVIEW, AllView.class);
        navigator.addView(APPLICATIONSVIEW, ApplicationsView.class);
        navigator.addView(HARDWAREVIEW, HardwareView.class);

    }

    @WebServlet(urlPatterns = "/*", name = "MyUIServlet", asyncSupported = true)
    @VaadinServletConfiguration(ui = MyUI.class, productionMode = false)
    public static class MyUIServlet extends VaadinServlet {
    }
}
import com.vaadin.navigator.View;
import com.vaadin.navigator.ViewChangeListener;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.Label;

public class AllView extends CustomComponent implements View {

    public AllView() {
        setCompositionRoot(new Label("AllView"));
    }

    @Override
    public void enter(ViewChangeListener.ViewChangeEvent event) {
    }
}
import com.vaadin.navigator.View;
import com.vaadin.navigator.ViewChangeListener;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.Label;

public class HardwareView extends CustomComponent implements View {
    public HardwareView() {
      setCompositionRoot(new Label("HardwareView"));
    }

    @Override
    public void enter(ViewChangeListener.ViewChangeEvent event) {
    }
}

[code]
import com.vaadin.navigator.View;
import com.vaadin.navigator.ViewChangeListener;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.Label;

public class ApplicationsView extends CustomComponent implements View {

    public ApplicationsView() {
        setCompositionRoot(new Label("ApplicationsView"));
    }

    @Override
    public void enter(ViewChangeListener.ViewChangeEvent event) {
    }
}
[/code]

The Errors:

java.lang.RuntimeException: Uncompilable source code - Erroneous tree type: <any>

java.lang.IllegalArgumentException: Trying to navigate to an unknown state 'allView' and an error view provider not present
    at com.vaadin.navigator.Navigator.navigateTo(Navigator.java:560)

java.lang.IllegalArgumentException: Trying to navigate to an unknown state 'applicationsView' and an error view provider not present
    at com.vaadin.navigator.Navigator.navigateTo(Navigator.java:560)

java.lang.IllegalArgumentException: Trying to navigate to an unknown state 'hardwareView' and an error view provider not present
    at com.vaadin.navigator.Navigator.navigateTo(Navigator.java:560)

I’m very thankful for every help.
Elia

Hi,

You have to add a “default” view. For example:

navigator.addView("", DefaultView.class);

Notice the empty string set as the view name.

can you show full stack trace? I guess the real problem is hidden :slight_smile:

Meanwhile you can try StaticViewProvider. just pass a instance instead of view class. like this

navigator.addView(“”, new StartView());
navigator.addView(MAINVIEW, new MainView());

Thanks for every help. I had troubles with compile the program and the mavenlibrarys.

What kind of trouble did you have?

I downloaded the librarys and compile my programcode once again. Then the views are working. Thanks