ragunathjawahar / android-saripaar

UI form validation library for Android
Apache License 2.0
3.22k stars 460 forks source link

Fatal Exception: java.lang.NullPointerException #213

Open AliTaylor1 opened 6 years ago

AliTaylor1 commented 6 years ago

I'm really struggling to recreate this validation issue where some somehow the ValidatorContext losses context. Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.mobsandgeeks.saripaar.ValidationContext.setViewRulesMap(java.util.Map)' on a null object reference at com.mobsandgeeks.saripaar.Validator.createRulesSafelyAndLazily(Validator.java:479)

traitaodoc1994 commented 6 years ago

have you solved it?

xionger0520 commented 6 years ago

@AliTaylor1 @traitaodoc1994 @ragunathjawahar can you tell me how to solve it? I had the same problem.

Puneet1796 commented 4 years ago

Hey, I found the solution around this. Compare your validator initialization with the bottom code snippet. Validator validator = new Validator(this); Always pass this as its controller reference. If you're trying to pass getContext()/requireContext() or getActivity()/requireActivity() then somehow It won't be able to figure out on which class you are try to associate your validator.

I hope it helps. Happy Coding! </>