java.lang.NullPointerException: null when add value to model play framework

300 views Asked by At

i am new to play framework, i try add new value to my model in my controller and i got java.lang.NullPointerException: null

this is my model

public class DokumenKeluarFileModel extends Model {

public DokumenKeluarModel keluar;
public DokumenMasukModel masuk;

@Formats.DateTime(pattern="dd/MM/yyyy")
public Date tanggal;

public static Finder<Long, DokumenKeluarFileModel> find = new finder(Long.class, DokumenKeluarFileModel.class);

 public static String save(DokumenKeluarFileModel dok){
    try {
        dok.save();
        return "Success";
    }catch (Exception e){
        return "Failed to save data, error message : "+e.getMessage();
    }
  }
}

this is my controller

public static String saveDoc(Form<DokumenKeluarModel> formKel){

    String status = "";

        for(DokumenMasukModel doc: candidateUnique){
            DokumenKeluarFileModel kelFile = new DokumenKeluarFileModel();

            kelFile.keluar.id = formKel.get().id;
            kelFile.masuk.id = doc.id;
            kelFile.tanggal = formKel.get().tanggal;
            status = DokumenKeluarFileModel.save(kelFile);
            if(!status.equals("Success")){
                flash("ermsg",status);
                break;
            }
        }

    return status;
}

I got error java.lang.NullPointerException: null and in debugger i found this

kelFile.masuk.id = java.lang.NullPointerException

kelFile.keluar.id = java.lang.NullPointerException

i think this error relate to my problem. Did i wrong when declare my model?

0

There are 0 answers