mercredi 5 avril 2017

Why do I get a NullPointerException in this if-statement [duplicate]

This question already has an answer here:

I have created the following code:

    String lVakCode = lJsonObjectIn.getString("vakCode");
    String lKlasCode = lJsonObjectIn.getString("klasCode");

    for (Les l : informatieSysteem.getDeLessen()) {
        if (l.getHetVak().getVakCode().equals(lVakCode) &&    //<--NullPointerException here
                l.getDeKlas().getKlasCode().equals(lKlasCode) &&
                l.getDatum().equals(lDatum)) {
            System.out.println("les gevonden");    //<--This still executes
        }
    }

When I run this I get an NullPointerException at the if-statement, but I also get the line I print to the console to see if it worked. How does this happen? How come I get an exception, but the code inside the if-statement still executes? Any help would be appreciated.

Aucun commentaire:

Enregistrer un commentaire