Calculate total overtime

Hi There,

I have two screen, one in which i calculate the ovetime per user per day, with this code:

public class OverwerkRegelsEdit extends AbstractEditor {

@Override
protected boolean preCommit() {
    BigDecimal aantalUren = getItem()
            .getEinde()
            .subtract(BigDecimal.valueOf(getItem().getAanvang()));
    getItem().setAantalUren(aantalUren);
    return super.preCommit();
}

}

And the other screen where i want to calculate the total sum of overtime per user in a month, with this code:

public class OverwerkEdit extends AbstractEditor {

@Inject
private CollectionDatasource<OverwerkRegels, UUID> overwerkRegelsDs;

@Override
public void init(Map<String, Object> params) {
}

@Override
public void ready() {
    overwerkRegelsDs.addCollectionChangeListener(e -> getItem().setTotaalOverwerkUren(calculateTotaalOverwerkUren()));
}

private BigDecimal calculateTotaalOverwerkUren() {

    BigDecimal totaalOverwerkUren = BigDecimal.ZERO;

    if (getItem().getOverwerkRegels() != null)
        totaalOverwerkUren =
                getItem().getOverwerkRegels().stream()
                        .map(OverwerkRegels::getAantalUren)
                        .reduce(BigDecimal.ZERO, BigDecimal::add);

    return totaalOverwerkUren;
}

}

When i go to the edit screen I get “a null pointer exception error”.
Also whe i want to create a new line i get “ClassCastException: com.company.grs.entity.Overwerk cannot be cast to java.util.Collection”.

I used both codes once in cuba studio 6, but in cuba 7 it doesnt seem to want to work.

Can someone please help me?

Regards,

LS

Hi,
If the exception falls in the code of your project, you should use debugger. Put a breakpoint in the code. When the local debug Tomcat server is running, breakpoint will trigger and will be able investigate context variables and understand why code is not working the way it should.
Take a look at this video: Debugging in IntelliJ - YouTube

As you have not given stack trace for these two exceptions, it is impossible to advice anything else.

1 Like