Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 304
  • Last Modified:

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);
            
      

            if(!errors.hasErrors())
            {
                  CompProgramServiceImpl compPrImp = new CompProgramServiceImpl();
                  try {
                        String compId = compPrImp.addCompProgram(compProg);
                  }
                  catch(Exception e)
                  {
                        //throw new Exception();
                  }

            }
    }      

-------------
CompProgramController.java
CompProgramValidator.java
0
manu112233
Asked:
manu112233
1 Solution
 
Sathish David Kumar NCommented:
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
0
 
Sathish David Kumar NCommented:
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
0
 
dearkasiCommented:
Hi,

Put a null check while using errors. Replace the line with '  if(!errors.hasErrors())' with '  if(null != errors && !errors.hasErrors())'.
0
 
Mahesh BhutkarCommented:
I suggest to initialize errors object.
0
 
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.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now