Hello, I am getting the below error while accessing the page. java.lang.Nul

Hello,
I am getting the below error while accessing the page.
java.lang.NullPointerException
at org.vaadin.klaudeta.PaginatedGrid.doCalcs(PaginatedGrid.java:53)
at org.vaadin.klaudeta.PaginatedGrid.onAttach(PaginatedGrid.java:45)

i am a new for vaadin and not sure am i doing any mistakes.

Thank you.

Hi,
Can you give a bit of more details/code on how you are trying to use the component?

Thank you for your reply.

PaginatedGrid grid = new PaginatedGrid<>();
public MainView(@Autowired …,@Autowired …) {
add(grid);
}

 private void updateGrid(TextField textField, DatePicker dfFromDate, DatePicker dfToDate, ...., .....,
		......) {
		 List<CounterSummary> result = counterSummaryRepository.reportQueryShortid(counterName, from, until, pageRequest);
    System.out.println("SQL request has finished");
    
    if(result != null && result.size()!=0) {        	
    	  
    grid.getColumns().forEach(grid::removeColumn);

    grid.setItems(result.size() >= pageSize ? result.subList(0, pageSize - 1) : result);
   
    lastFetchNumber = result.size();

    grid.addColumn(counterSummary -> simpleDateFormat.format(counterSummary.getRequestDate())).setHeader("Date");
    grid.addColumn(counterSummary -> shortid.getShortid()).setHeader("ShortId").setResizable(true);
    grid.addColumn(counterSummary -> counterName.getCounterName()).setHeader("Breadcrumb").setResizable(true);
    grid.addColumn(counterSummary -> counterSummary.getPageRequests() != null ? counterSummary.getPageRequests().toString() : "").setHeader("Pagerequests").setFlexGrow(10);
    grid.addColumn(counterSummary -> counterSummary.getPageVisitors() != null ? counterSummary.getPageVisitors().toString() : "").setHeader("Visitors").setFlexGrow(10);
    grid.addColumn(counterSummary -> counterSummary.getPageRequests() != null ? counterSummary.getPageRequests().toString() : "").setHeader("Pagerequests").setFlexGrow(10);
    grid.addColumn(counterSummary -> counterName.getCountryCode().getCountryCode()).setHeader("Language").setFlexGrow(10);
   
    // Sets the max number of items to be rendered on the grid for each page
	grid.setPageSize(15);
	
	// Sets how many pages should be visible on the pagination before and/or after the current selected page
	grid.setPaginatorSize(5);
    
	
    grid.getDataProvider().refreshAll();
      
    System.out.println("<><><>finished<><><>");
		
		}

While accessing the below url in browser throws error…
http://localhost:8080/

Thank you.

Hi,
It is actually a bug. Thanks for your help identifying it.

It happens when grid.setItem is being called after the grid has already been attached/added into the layout. I’ll fix it of course but meanwhile as a workaround can you call the grid.setItem before you actually add the grid into the layout.

Another thing I noticed in you code above is that you are doing this

grid.setItems(result.size() >= pageSize ? result.subList(0, pageSize - 1) : result);

instead of just

grid.setItem(result);

In you case the grid will always have just one page, but if you normally set the result as they are with grid.setItem(result) then the internal of the PaginatedGrid with take care of doing the calculations.