所以,这是我的代码

import java.util.regex.Matcher;
import java.util.regex.Pattern;


public class EmailCheck
{

    public static boolean isValid(String email)
    {

        String emailRegex = "^[a-zA-Z0-9_+&*-]+(?:\\."+
                            "[a-zA-Z0-9_+&*-]+)*@" +
                            "(?:[a-zA-Z0-9-]+\\.)+[a-z" +
                            "A-Z]{2,7}$";

        Pattern pat = Pattern.compile(emailRegex);
        if (email == null)
            return false;
        return pat.matcher(email).matches();
    }
}


然后


public class EmailChecker extends EmailCheck
{

   public EmailChecker(String email)
   {

      if (isValid(email))
      {
            System.out.print(email+" is an email address");
      }
      else
      {
            System.out.print(email+" is not an email address");
      }
   }
}


和主要的

import java.util.Scanner;
public class EmailInput
{
    public static void main (String[] args)
    {

        Scanner scan = new Scanner(System.in);
        String email = scan.nextLine();
        EmailChecker active = new EmailChecker(email);
        active.EmailChecker();
    }
}


因此,基本上,我想创建一个程序来要求用户输入电子邮件,然后该程序将检查电子邮件是否有效,并且我的讲师还告诉我,还需要这样创建电子邮件(具有1类,然后再扩展它和主体)。
但是似乎如果我尝试编译它,它将给我错误

C:\Java 2>javac EmailInput.java
EmailInput.java:10: error: cannot find symbol
                active.EmailChecker();
                      ^
  symbol:   method EmailChecker()
  location: variable active of type EmailChecker
1 error


有人知道如何解决该错误吗?

最佳答案

您必须更改:

1.主要

EmailChecker active = new EmailChecker();
active.checkEmailChecker(email);


2. EmailChecker

public void checkEmailChecker(String email)


要么:
1.仅主要:

EmailChecker active = new EmailChecker(email);


2. EmailChecker:

public EmailChecker(String email)


展位正在工作。解决方案是您的逻辑在构造函数中。因此,您没有功能“ active.EmailChecker();”

关于java - 如何解决错误:找不到符号(示例处于 Activity 状态。EmailChecker();箭头指向“。”),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/60833484/

10-11 00:59