-4

I am deeply confused that why I am getting null pointer exception in this code.

code:

Integer branchid = gd.getBranchid();//Getting null pointer exception in this line(234)
if(branchid != null)
    clm.setBranchId(branchid);
else
    clm.setBranchId(0);

Exception:

  java.lang.NullPointerException
at com.ctl.addCampaign.CampaignController.saveCustomeridAndMobileNoNew(CampaignController.java:234)
Federico klez Culloca
  • 24,336
  • 15
  • 57
  • 93
vgc1850
  • 1
  • 2
  • It either means that `gd` is null or that something inside the `getBranchid` method is throwing the exception. It's a bit hard to help you without a stack trace and without knowing what `gd` is. – Federico klez Culloca May 25 '22 at 09:31
  • Which line is throwing the exception? It’ll be because either `gd` and/or `clm` is null. – racraman May 25 '22 at 09:32
  • gd is a object of list – vgc1850 May 25 '22 at 09:34
  • 1
    `gd` is null. When you try to invoke a method on a null object, you end up with that exception. Not sure why that is so deeply confusing. – GhostCat May 25 '22 at 09:34
  • 1
    It doesn't matter how `gd` is **declared** in your code. The only thing that matters is: at RUNTIME, for whatever reason, that object is NULL. Maybe you didn't initialize it, or your did, but then set it to null for whatever reason. That is all there is to this. Step back, and read that duplicated question recommended to you. Yes, a lot of information ... but still worth reading. – GhostCat May 25 '22 at 09:35
  • Post your question with sufficient information. – DEBENDRA DHINDA May 25 '22 at 10:27

0 Answers0