mardi 2 avril 2019

Handle NullPointerException in if statement java [duplicate]

This question already has an answer here:

So I created a method to check if fields are different to determine if user can update template. Of course I used .equals to check if values differ. But now it gives me NullPointerException when I try to test the code. Do you have some great solution to this?

private boolean diff(Document doc, Document temp)
    {
        return (!(temp.getAccount().equals(doc.getAccount())
        || temp.getName().equals(doc.getName())
        || temp.getAddress().equals(doc.getAddress())
        || temp.getLastname().equals(doc.getLastname())
        || temp.getNumber().equals(doc.getNumber())));
    }

This is where I get the error:

assertThat(generator.diff(temp, doc), is(true)); 

java.lang.NullPointerException at UpdatedTemplateTest.java:28

Aucun commentaire:

Enregistrer un commentaire