V7 Grid Filter throws NPE When pressed enter

Hi guys,

Do you have any clue why the V7 Grid Filter throws NPE When pressed entered. The sample code looks something like this:


// Create a header row to hold column filters
HeaderRow filterRow = grid.appendHeaderRow();

// Set up a filter for all columns
for (Object pid: grid.getContainerDataSource()
                     .getContainerPropertyIds()) {
    HeaderCell cell = filterRow.getCell(pid);

    // Have an input field to use for filter
    TextField filterField = new TextField();
    filterField.setColumns(8);
    filterField.setInputPrompt("Filter");
    filterField.addStyleName(ValoTheme.TEXTFIELD_TINY);

    // Update filter When the filter input is changed
    filterField.addTextChangeListener(change -> {
        // Can't modify filters so need to replace
        container.removeContainerFilters(pid);

        // (Re)create the filter if necessary
        if (! change.getText().isEmpty())
            container.addContainerFilter(
                new SimpleStringFilter(pid,
                    change.getText(), true, false));
    });
    cell.setComponent(filterField);
}

Can you share the stack trace?

I fixed the Null pointer exception…however it seems that the pressing Enter key does not do the filtering?

Do we have to

removeAllFilters(); and then addItem

 java.util.concurrent.ExecutionException: java.lang.NullPointerException; cause: java.lang.NullPointerException
java.util.concurrent.ExecutionException: java.lang.NullPointerException
	at java.util.concurrent.FutureTask.report(FutureTask.java:122)
	at java.util.concurrent.FutureTask.get(FutureTask.java:192)
	at com.vaadin.server.VaadinSession$FutureAccess.get(VaadinSession.java:124)
	at com.vaadin.server.VaadinService.runPendingAccessTasks(VaadinService.java:1849)
	at com.vaadin.server.VaadinSession.unlock(VaadinSession.java:992)
	at com.vaadin.server.VaadinService.ensureAccessQueuePurged(VaadinService.java:1809)
	at com.vaadin.server.VaadinService.accessSession(VaadinService.java:1775)
	at com.vaadin.server.VaadinSession.access(VaadinSession.java:1384)
	at com.vaadin.ui.UI.access(UI.java:1455)
	at com.example.vaadin.ui.gsearch.SearchThread.run(SearchThread.java:78)
Caused by: java.lang.NullPointerException
	at com.exxample.vaadin.ui.gsearch.MySearchResultsGrid.updateContainer(MySearchResultsGrid.java:258)
	at com.example.vaadin.ui.gsearch.SearchThread.handleQueryResult(SearchThread.java:52)
	at com.example.vaadin.ui.gsearch.SearchThread.lambda$run$1(SearchThread.java:78)
	at com.vaadin.ui.UI.accessSynchronously(UI.java:1392)
	at com.vaadin.ui.UI$4.run(UI.java:1458)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at com.vaadin.server.VaadinService.runPendingAccessTasks(VaadinService.java:1846)
	... 6 more

I can see there’s a NPE at MySearchResultsGrid.java:258. Can you share that part of the code?

On line 258, I have fetched itemId with property “Name”, so it is delcared like this:
container.getItem(itemId).getItemProperty("Name").setValue(name);

Before this, I declared it like this:

	Object itemId = container.addItem();

Shoudn’t it be getItemProperty("name") with a lowercase “n”?

I think that will throw again NPE …with long stack trace.

Add a breakpoint at that line and see what exactly is null.