non-static method matcher(CharSequence) cannot be referenced from a static context

Brendan

I keep running into this error whenever I build projects on Android Studio:

non-static method matcher(CharSequence) cannot be referenced from a static context

The error occurs at line 9: matcher = Pattern.matcher(email);

This is my code:

//Email Validation using Regex

public boolean emailChecker(String email){
    Pattern pattern;
    Matcher matcher;

    final String EMAIL_PATTERN = "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
    pattern = Pattern.compile(EMAIL_PATTERN);
    matcher = Pattern.matcher(email);
    return matcher.matches();
}
Kushan

You've used Pattern.matcher which is the class name

Use:

pattern.matcher(yourinput); //pattern is your compiled pattern variable

Also i would suggest the built in pattern in android to avoid any regex errors

public final static boolean isValidEmail(CharSequence target) {
  return (!TextUtils.isEmpty(target) && Patterns.EMAIL_ADDRESS.matcher(target).matches())
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

non static method cannot be referenced from a static context

From Dev

non-static method getIntent() cannot be referenced from a static context

From Dev

"Non-static method cannot be referenced from static context" error

From Dev

Non-static method getSocketFactory cannot be referenced from a static context

From Dev

Error:non static method 'edit' cannot be referenced in static context

From Dev

Trying to get my show-method to work (Non static method cannot be referenced from static context)

From Dev

non-static variable s cannot be referenced from a static context

From Dev

non static variable this cannot be referenced from a static context

From Java

"non-static variable this cannot be referenced from a static context"?

From Java

non-static class cannot be referenced from a static context

From Dev

java: non-static variable this cannot be referenced from a static context

From Dev

Non-static variable filepath cannot be referenced from a static context

From Dev

Non static variable cannot be referenced from static context java

From Dev

non-static variable cannot be referenced from static context [JAVA]

From Dev

non-static variable cannot be referenced from a static context java

From Dev

Non-static edit() cannot be referenced from a static context

From Dev

non static setGravity cannot be referenced from static context

From Dev

Non-static variable cannot be referenced from a static context?

From Dev

Map.merge .. non-static method cannot be referenced from static context

From Java

Why does String::isEmpty works when non-static method cannot be referenced from a static context?

From Java

java - Non-static method 'getLogger' cannot be referenced from a static context

From Dev

non-static method count(int) cannot be referenced from a static context

From Dev

Non-static method cannot be referenced from a static context when flattening map java 8

From Java

Non static field cannot be referenced from a static context- Main method

From Java

Non-static method cannot be referenced from a static context in java 8 streams

From Java

Non-static method cannot be referenced from a static context in java 8 streams

From Dev

Flutter: non-static method registerWith(Registrar) cannot be referenced from a static context

From Java

Error: Non-static method 'findViewById(int)' cannot be referenced from a static context

From Java

Android: Non-static method cannot be referenced from static context. Confused?

Related Related

  1. 1

    non static method cannot be referenced from a static context

  2. 2

    non-static method getIntent() cannot be referenced from a static context

  3. 3

    "Non-static method cannot be referenced from static context" error

  4. 4

    Non-static method getSocketFactory cannot be referenced from a static context

  5. 5

    Error:non static method 'edit' cannot be referenced in static context

  6. 6

    Trying to get my show-method to work (Non static method cannot be referenced from static context)

  7. 7

    non-static variable s cannot be referenced from a static context

  8. 8

    non static variable this cannot be referenced from a static context

  9. 9

    "non-static variable this cannot be referenced from a static context"?

  10. 10

    non-static class cannot be referenced from a static context

  11. 11

    java: non-static variable this cannot be referenced from a static context

  12. 12

    Non-static variable filepath cannot be referenced from a static context

  13. 13

    Non static variable cannot be referenced from static context java

  14. 14

    non-static variable cannot be referenced from static context [JAVA]

  15. 15

    non-static variable cannot be referenced from a static context java

  16. 16

    Non-static edit() cannot be referenced from a static context

  17. 17

    non static setGravity cannot be referenced from static context

  18. 18

    Non-static variable cannot be referenced from a static context?

  19. 19

    Map.merge .. non-static method cannot be referenced from static context

  20. 20

    Why does String::isEmpty works when non-static method cannot be referenced from a static context?

  21. 21

    java - Non-static method 'getLogger' cannot be referenced from a static context

  22. 22

    non-static method count(int) cannot be referenced from a static context

  23. 23

    Non-static method cannot be referenced from a static context when flattening map java 8

  24. 24

    Non static field cannot be referenced from a static context- Main method

  25. 25

    Non-static method cannot be referenced from a static context in java 8 streams

  26. 26

    Non-static method cannot be referenced from a static context in java 8 streams

  27. 27

    Flutter: non-static method registerWith(Registrar) cannot be referenced from a static context

  28. 28

    Error: Non-static method 'findViewById(int)' cannot be referenced from a static context

  29. 29

    Android: Non-static method cannot be referenced from static context. Confused?

HotTag

Archive