Skip to content
Advertisement

NullPointerException on validating email

I am writing a unit test to check the email validation logic. The logic is throwing null pointer exception when you run the test. But it works fine with emulator. Can someone help me solving this?

JavaScript

Below is my unit test.

JavaScript

The error I am getting is,

JavaScript

Advertisement

Answer

android.util.Patterns.EMAIL_ADDRESS.matcher(email).matches() exists since API level 8, May be your emulator is prior than this.

So I suggest Adding custom EMAIL_ADDRESS_PATTERN string as suggested in this answer and check it like

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement