0

Good morning everyone please I am having a null pointer exception on my repository any help will be appreciated thank you in advance.

here is my repository

@Repository
public interface VCashPopUpRepository extends MongoRepository<VCashTopUp, String> {
     VCashTopUp findByTransactionID(String transactionID);
}

here is my service

if (responseResult.equals("00")) {
  logger.info("SessionId {} About to update final status in VCashTopUp", sessionId);
  try {
        VCashTopUp vCashTopUp = vCashPopUpRepository.findByTransactionID(transactionId);
        logger.info("SessionId = {} TransactionId found", sessionId);
  
       if (vCashTopUp == null) continue;
       vCashTopUp.setFinalStatus("Success");
 
       logger.info("SessionId ={} Done updating final status in VCashTopUp", sessionId);

    } catch (Exception e) {
         logger.error("SessionId ={} Inside Buy Airtime exception",sessionId);
         e.printStackTrace();
    }
                                        }

Here is my model

@Document(collection = "VCashTopUp")
public class VCashTopUp {

    @Id
    private String _id;
    private String receiveMsisdn;
    private String amount;
    private String transactionID;
    private String initiatingMsisdn;
    private String finalStatus;

   getters and setters...
BALDE
  • 27
  • 5
  • 3
    Can you add the error stack trace? Thanks – João Dias Oct 25 '21 at 11:16
  • 1
    error stacktrace as @JoãoDias mentioned and please post the full body of your service that calls your repository. – pleft Oct 25 '21 at 11:25
  • Also show the code, where the service is used (i.e. do you create an instance of the service class yourself, or is it maintained by Spring)? Most likely the latter is the problem (as it usually is with NullPointerExceptions around Spring beans) – dunni Oct 25 '21 at 15:13
  • java.lang.NullPointerException at gh.com.vodafone.vgil.VgilPayBillLogger.service.MCasBrokerService.readBrokerData(MCasBrokerService.java:199) at gh.com.vodafone.vgil.VgilPayBillLogger.VgilPayBillLoggerApplication.main(VgilPayBillLoggerApplication.java:16) – BALDE Oct 25 '21 at 17:01
  • Then we need the complete `MCasBrokerService` code. We can't help you simply by imagining what code you have there. You can't expect someone to be able to help you without providing all relevant information, keep this in mind while creating questions in SO. – João Dias Oct 25 '21 at 17:35
  • Just add the code for MCasBrokerService (preferably the method, where line 199 is), and for VgilPayBillLoggerApplication. – dunni Oct 25 '21 at 21:01
  • I have solved my issue, I was calling the service in the application main, instead of calling it through a controller. thank you all – BALDE Oct 26 '21 at 12:25

0 Answers0