NullPointer at Navigator

Hi everybody! I’m newbiew in Vaadin, and just got stucked in a problem. I’m doing a Vaadin book examples. At the moment, this one:

link

I wondered what if I don’t want to use nested classes, because it can be a disaster if those codes are long and curly. So I made two classes in the package: StartView class and MainView class and of theese classes’s code lines deleted. Everything remained the same. But when I hit the button to reach the main menu, the program crashes with a null pointer exception which says I have a problem at the StartView class (this is only the button to the main menu) at this line:


public void buttonClick(ClickEvent event) {
				navigator.navigateTo(MAIN_VIEW);
				
			}

What can be wrong? I have to use nested classes for navigation in views?

to access the navigator if the view class is not nested, you can do it like this:

UI.getCurrent().getNavigator().navigateTo(MAINVIEW);

Thanks works like charm :slight_smile: