title: java.lang.NullPointerException when sending object to Service
body: <p>Hy,</p>
  
  <p>Im actually developping an app that could read feilds inside a file and record them into the database using spring,J2EE, Hibernate and Mysql, but i've got a probleme when tring to send the retreived fields (object) into the service i get a java.lang.NullPointerException error.</p>
  
  <p>this is the file reader code :</p>
  
  <pre><code>    import Infradashboard.Infradashboard.Entities.Call;
      import Infradashboard.Infradashboard.Services.CallService;
      import org.springframework.beans.factory.annotation.Autowired;
  
      import java.io.BufferedReader;
      import java.io.FileReader;
  
      public class FileOperationCdr {
  
  
      @Autowired
      CallService callService;
  
      public void loadCdrValues() throws Exception {
  
      //Read CDR File
        BufferedReader in = new BufferedReader(new FileReader(
              "/home/rida/IdeaProjects/CDR_SM/S000A4B-D40E-180805-05_47"));
  
      //Buffer to store file contents
      StringBuffer fileContentBuffer = new StringBuffer();
  
      String str;
      while ((str = in.readLine()) != null) {
          //If empty line, replace it with comma in buffer
          if (str.equals("")) {
              fileContentBuffer.append(",");
          }
  
          //Add line to file buffer
          fileContentBuffer.append(str);
      }
  
      //Split file contents with comma delimiter and store in an array
      //This provides each CDR record as array element
      String[] contentArray = fileContentBuffer.toString().split(",");
  
      //Main object to be stored in db
      //This will contain start, stop and interim-update details
  
      //Iterate through CDR content
      for (int i = 0; i &lt; contentArray.length; i++) {
          if (contentArray[i].length() &gt; 0) {
              //Split the content array with "TAB" delimiter to get all values of the data
              String[] innerArray = contentArray[i].split("\t");
  
              //Local object to store data values
              Call innerObject = new Call();
  
              String timedayminutes = (innerArray[0].substring(innerArray[0].lastIndexOf(":") + 1));
              String datemounth = (innerArray[0].split("/")[0]).toString();
              String dateday = (innerArray[0].substring(innerArray[0].lastIndexOf("/") + 1));
              String durationhours = (((innerArray[0].substring(innerArray[0].lastIndexOf("/") + 1))).substring(6,7));
              String durationminutes = (((innerArray[0].substring(innerArray[0].lastIndexOf("/") + 1))).substring(7,9));
              String durationsecondes = (((innerArray[0].substring(innerArray[0].lastIndexOf("/") + 1))).substring(9,11));
              String durationmilliseconds = (((innerArray[0].substring(innerArray[0].lastIndexOf("/") + 1))).substring(11,14));
              String conditioncode = (((innerArray[0].substring(innerArray[0].lastIndexOf("/") + 1))).substring(14,15));
              String dialednumber = ((((innerArray[0].substring(innerArray[0].lastIndexOf("/") + 1))).substring(16))).split(" ")[0];
              String callingnumber = ((((innerArray[0].substring(innerArray[0].lastIndexOf("/") + 1))).substring(32))).split(" ")[0];
              String destinationsip = ((((innerArray[0].substring(innerArray[0].lastIndexOf("/") + 1))).substring(48))).split(" ")[0];
              String orginatingsip = ((((innerArray[0].substring(innerArray[0].lastIndexOf("/") + 1))).substring(81))).split(" ")[0];
              String feautureflag = ((((innerArray[0].substring(innerArray[0].lastIndexOf("/") + 1))).substring(114))).split(" ")[0];
              String BCC = ((((innerArray[0].substring(innerArray[0].lastIndexOf("/") + 1))).substring(116,117)));
              String MAUUI = ((((innerArray[0].substring(innerArray[0].lastIndexOf("/") + 1))).substring(117,118)));
              String resourceflag = ((((innerArray[0].substring(innerArray[0].lastIndexOf("/") + 1))).substring(118,119)));
              String bandwidth = (((((innerArray[0].substring(innerArray[0].lastIndexOf("/") + 1))).substring(120,122)))).replaceAll("\\D+","");
              String avgsid = ((((innerArray[0].substring(innerArray[0].lastIndexOf("/") + 1))).substring(123))).split(" ")[0];
              String callingipadresse = ((((innerArray[0].substring(innerArray[0].lastIndexOf("/") + 1))).substring(160,174))).split(" ")[0];
              String calledipadresse = ((((innerArray[0].substring(innerArray[0].lastIndexOf("/") + 1))).substring(176,190)));
              String voicecall = ((((innerArray[0].substring(innerArray[0].lastIndexOf("/") + 1))).substring(192,193)));
              String videocall = ((((innerArray[0].substring(innerArray[0].lastIndexOf("/") + 1))).substring(193,194)));
              String faxcall = ((((innerArray[0].substring(innerArray[0].lastIndexOf("/") + 1))).substring(194,195)));
              String textcall = ((((innerArray[0].substring(innerArray[0].lastIndexOf("/") + 1))).substring(195,196)));
              String othercall = ((((innerArray[0].substring(innerArray[0].lastIndexOf("/") + 1))).substring(196,197)));
              String codec = ((((innerArray[0].substring(innerArray[0].lastIndexOf("/") + 1))).substring(198,200))).replaceAll("\\D+","");
              String callingpartyid = "No";
              String calledpartyid = "No";
              String carriagereturn = "NO";
  
  
  
              innerObject.setTimeofdayhours(Integer.parseInt((innerArray[0].split(":")[0]).toString()));
              innerObject.setTimeofdayminutes(Integer.parseInt((timedayminutes.split(" ")[0]).toString()));
              innerObject.setDateofyearmounth(Integer.parseInt((datemounth.substring(datemounth.lastIndexOf(" ") + 1)).toString()));
              innerObject.setDateofyearday(Integer.parseInt((dateday.substring(0, 2)).toString()));
              innerObject.setDurationhours(Integer.parseInt(durationhours.toString()));
              innerObject.setDurationminutes(Integer.parseInt(durationminutes.toString()));
              innerObject.setDurationseconds(Integer.parseInt(durationsecondes.toString()));
              innerObject.setDurationmilliseconds(Integer.parseInt(durationmilliseconds.toString()));
              innerObject.setConditioncode(conditioncode.toString());
              innerObject.setDialednumber(dialednumber.toString());
              innerObject.setCallingnumber(callingnumber.toString());
              innerObject.setTerminatingSIPEntity(destinationsip.toString());
              innerObject.setOriginatingSIPEntity(orginatingsip.toString());
              innerObject.setFeatureflag(feautureflag.toString());
              innerObject.setBCC(BCC.toString());
              innerObject.setMAUUI(MAUUI.toString());
              innerObject.setResourceflag(resourceflag.toString());
              innerObject.setBandwidth(Integer.parseInt(bandwidth.toString()));
              innerObject.setAvGSID(avgsid.toString());
              innerObject.setCallingPartyIP(callingipadresse.toString());
              innerObject.setCalledPartyIP(calledipadresse.toString());
              innerObject.setCallusagevoice(voicecall.toString());
              innerObject.setCallusagevideo(videocall.toString());
              innerObject.setCallusagefax(faxcall.toString());
              innerObject.setCallusagetext(textcall.toString());
              innerObject.setCallusageother(othercall.toString());
              if (codec.equals(""))
              {
                  innerObject.setCodec(Integer.parseInt("0"));
              }
              else
              {
  
              innerObject.setCodec(Integer.parseInt(codec.toString()));
              }
              innerObject.setCallingpartyid(callingpartyid.toString());
              innerObject.setCalledpartyid(calledpartyid.toString());
              innerObject.setCarriagereturn(carriagereturn.toString());
  
                      callService.createCall(innerObject);
       }
      }
      }
  </code></pre>
  
  <p>The service :</p>
  
  <pre><code>    import Infradashboard.Infradashboard.Entities.Call;
      import org.springframework.http.ResponseEntity;
      import org.springframework.stereotype.Service;
      import java.util.List;
  
      @Service
      public interface CallService {
          List&lt;Call&gt; getAllCalls();
  
          Call getCallById(Integer callId);
  
          Call createCall(Call call);
  
          Call updateCall(Integer callId, Call callDetails);
  
      }
  </code></pre>
  
  <p>The service implimentation :</p>
  
  <pre><code>    import Infradashboard.Infradashboard.Entities.Call;
      import Infradashboard.Infradashboard.Repository.CallRepository;
      import org.springframework.beans.factory.annotation.Autowired;
      import org.springframework.http.ResponseEntity;
      import org.springframework.stereotype.Service;
      import java.util.List;
  
      @Service
      public class CallServiceImp implements CallService {
  
          @Autowired
          CallRepository callRepository;
  
          @Override
          public List&lt;Call&gt; getAllCalls() {
              return callRepository.findAll();
          }
  
          @Override
          public Call getCallById(Integer callId) {
              return callRepository.findById(callId)
                           .orElseThrow(() -&gt; new ResourceNotFoundException( "Call" , "Id" , callId));
          }
  
          @Override
          public Call createCall(Call call) {
              return callRepository.save(call);
          }
  
          @Override
          public Call updateCall(Integer callId, Call callDetails) {
         }
         } 
  </code></pre>
  
  <p>the File content :</p>
  
  <pre><code>    05:41 08/05
      054100000000N 0275600000      0505455134      ACM                              SBCE                4 M00  1 75f9e080-9861-11e8-abe2-0050569600f2 10.0.0.5      0.0.0.0         YNNNN       
  </code></pre>
  
  <p>the generated error :</p>
  
  <pre><code>     java.lang.NullPointerException
   at Infradashboard.Infradashboard.DAO.FileOperationCdr.loadCdrValues(FileOperationCdr.java:124)
   at Infradashboard.Infradashboard.InfradashboardApplication.main(InfradashboardApplication.java:17)
   at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
            at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
            at java.base/java.lang.reflect.Method.invoke(Method.java:564)
   at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
  </code></pre>
  
  <p>the code does work if i dont use the callservice.createcall(innerobject);
  is there another way to create the call innerobject without using the new call(), initializer ?                                                              </p>