Getting null pointer exception

Getting null pointer exception at erros object in below code.

public void doSubmitAction(Object command){
            System.out.println(" in CompProgramController");
            Errors errors = null;
            CompProgram compProg = (CompProgram)command;
            System.out.println("Comp Program:"+ compProg.getCompProgDesc());
            CompProgramValidator rcv = new CompProgramValidator();
            rcv.validate(compProg, errors);

                  CompProgramServiceImpl compPrImp = new CompProgramServiceImpl();
                  try {
                        String compId = compPrImp.addCompProgram(compProg);
                  catch(Exception e)
                        //throw new Exception();


Who is Participating?
Sathish David Kumar NConnect With a Mentor ArchitectCommented:
your validator method is not called !! so

error is null  as per declartion   ///    Errors errors = null;So this line give if(!errors.hasErrors()) null pointer exection
Sathish David Kumar NArchitectCommented:
Sorry your validator method nothing is return it dont have any error so it does not return anything

as per ur declartion ur error is null so its give null pointer exception

Put a null check while using errors. Replace the line with '  if(!errors.hasErrors())' with '  if(null != errors && !errors.hasErrors())'.
Mahesh BhutkarCommented:
I suggest to initialize errors object.
Kevin CrossChief Technology OfficerCommented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.