-3

I get a NullPointerException while running my webapplication, I save a logs and start server again and this error no longer there appeared, but i want protect method to NullPointer never appeared. I sure this line is responsible for this error

Vehicle pVehicle =
        Iterables.tryFind(aFactory.getVehicle(), new Predicate<Vehicle>() {
            @Override
            public boolean apply(Vehicle vehicle) {
                return vehicle.getVehicleBrand().equals(aVehicle.getVehicleBrand());
            }
        }).orNull();

But this is not my code, and i don't known, which part may cause this error> Please, which element can be appeared for this NullPointer and how protect this code

xenteros
  • 15,586
  • 12
  • 56
  • 91
Monika Galińska
  • 201
  • 1
  • 4
  • 11

2 Answers2

2

Check the following statements:

  • aFactory - Because of the getVehicle() call.
  • aFactory.getVehicle() - Because Iterables.tryFind expects a non-null Iterable
  • vehicle - Because of the getVehicleBrand() call
  • aVehicle - Because of the getVehicleBrand() call
  • vehicle.getVehicleBrand() - Because of the .equals() call

If any of these were null it would cause an NullPointerException

Kiskae
  • 24,655
  • 2
  • 77
  • 74
1

can generate null pointer :

aFactory.getVehicle() : if aFactory is null
vehicle.getVehicleBrand() : if vehicle is null
aVehicle.getVehicleBrand() : if aVehicle is null
BenB
  • 146
  • 1
  • 7