0

I am getting NullPointerException while calling a method: Xgenexport.java

Map agent_Details = commonLookupDAO.getAgentDetails(dQuoteDetails.getAgentId());

And the method in: Commonlookup dao:

public Map getAgentDetails(String agentId);

Commonlookupdaoimpl

public Map getAgentDetails(String agentId) {
    /*some code*/
    return resultMap;
}

Im getting NullPointerException while calling this method don't know the exact reason.

mike
  • 1
  • 3
  • So what exactly is at the line `XGenExportmotorcycle.java:281`? Is it the code which you posted first? If so, post a little more code, like where the Dao is injected. – dunni Oct 01 '16 at 07:44
  • yes that were i got null pointer exception – mike Oct 01 '16 at 07:48
  • my case is different this is not duplicate – mike Oct 01 '16 at 07:56
  • how you are creating obect `commonLookupDAO` – Shantaram Tupe Oct 01 '16 at 07:59
  • @mike - No. Your case is the same. That Q & A gives a >>general<< explanation of what an NPE is and a >>general<< approach to solving the problem. You apply it to your particular problem. – Stephen C Oct 01 '16 at 07:59
  • And for what it is worth, you have not shown us any evidence that would help us help you anyway. You need to 1) show us the stack trace, 2) show us the relevant code, 3) identify clearly the line of code at which the exception was thrown. – Stephen C Oct 01 '16 at 08:00
  • No i got little bit confused when im using a return type as string i can acces this method – mike Oct 01 '16 at 08:03
  • Now you are getting incomprehensible ...... – Stephen C Oct 01 '16 at 08:05
  • that means can you explain clearly – mike Oct 01 '16 at 09:05
  • show your code as asked by Stephen C – Shantaram Tupe Oct 01 '16 at 09:14
  • if(StringUtils.isNotBlank(dQuoteDetails.getAgentId())){ Map agent_details = commonLookupDAO.getAgentDetails(dQuoteDetails.getAgentId()); } – mike Oct 01 '16 at 09:30
  • Im getting null pointer when im calling getAgentdetails – mike Oct 01 '16 at 09:30
  • Method in Commonlookupdaoimpl: – mike Oct 01 '16 at 09:31
  • public Map getAgentDetails(String agentId) { LOGGER.info("agent details starts :::::::::"); Session session = getSessionFactory().getCurrentSession(); String oa_code = ""; String ag_code = ""; Map resultMap = new HashedMap(); try{ SQLQuery query = session.createSQLQuery("Select OA_CODE,AG_CODE from AGENT_MASTER where AGENT_ID= :agentId"); query.setParameter("agentId", agentId); List query_list = query.list(); – mike Oct 01 '16 at 09:32
  • when i changed the return type to String im not getting any exception.it works fine.. – mike Oct 01 '16 at 09:36
  • if any body can't understand my code plz revert me so that i can do the possible note.. – mike Oct 01 '16 at 09:37

1 Answers1

0

how you are creating obect commonLookupDAO

using Spring you may need to use Autowire it, if you are creating Single object of DAO class

Shantaram Tupe
  • 1,646
  • 3
  • 16
  • 42