Getting null pointer exception

Posted on 2011-02-21
Last Modified: 2013-11-11
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();


Question by:manu112233
LVL 20

Accepted Solution

Sathish David  Kumar N earned 500 total points
ID: 34942016
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
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 34942028
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

Expert Comment

ID: 35302261

Put a null check while using errors. Replace the line with '  if(!errors.hasErrors())' with '  if(null != errors && !errors.hasErrors())'.

Expert Comment

by:Mahesh Bhutkar
ID: 35873537
I suggest to initialize errors object.
LVL 59

Expert Comment

by:Kevin Cross
ID: 36935140
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
strCount chalenge 3 69
java set up 1 57
Non-recursive backtracking, using a stack 1 98
HSSFWorkbook cannot be resolved error 10 49
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now