NullPointerException when displaying table information

I’m testing the Navigator class and made a view that should display information of a table entry when it’s clicked. The ValueChangeListener has an Object called testId which is the id of the chosen entry. However, when I try to run the code below (which sets the label testName to equal the “Name” of the table entry), I get a NullPointerException:

public void enter(ViewChangeEvent event) {
// testName.setValue(event.getParameters());
testName.setValue(testTable.getItem(event.getParameters())
.getItemProperty(“Name”).getValue().toString());
}

java.lang.NullPointerException
at com.example.navigatortest.NavigatortestUI$TestView.enter(NavigatortestUI.java:213)
at com.vaadin.navigator.Navigator.navigateTo(Navigator.java:571)
at com.vaadin.navigator.Navigator.navigateTo(Navigator.java:526)
at com.example.navigatortest.NavigatortestUI$RoomView$ValueChangeListener.valueChange(NavigatortestUI.java:182)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

The error log suggests that the problem occurs in the setValue method. The commented out line above it runs fine as well and displays testId as it should.

Hi!

You should split up the parts and see what is actually null. My guess is that testTable.getItem(event.getParameters()) returns null. Does event.getParameters() actually contain the itemId for the table? (The itemId identifies a row in the table).

Another option is that you haven’t set the value for the property yet

I tested and found out that testTable.getItem(event.getParameters()) did indeed return null. However, event.getParameters() itself contains the id of the table entry as I said before, which is used to navigate to the view that’s supposed to display the table information. Here’s the code for the ValueChangeListener method if it helps:

class ValueChangeListener implements Property.ValueChangeListener {
Object testId;

        @Override
        public void valueChange(ValueChangeEvent event) {
            // Navigate to a chosen table entry
            this.testId = event.getProperty().getValue();
            navigator.navigateTo("test/" + testId);
        }

}