java - Android: Error in flow of passing through methods -


i trying pass text output regex method whereby can take entire text output , extract out email address.

for example, have text output below:

taria joseph general manager  96523325 tariajoseph@hotmail.com 

i want pass above text output regex method , extract out "tariajoseph@hotmail.com" , display edittext.

below codes:

public class createcontactactivityocrtest extends activity {  private string recognizedtext, texttouse; private edittext medittext1, medittext2; private string mfromlang, mcurrentlang;  private pattern pattern; private matcher matcher;  private static final string email_pattern =         "^[_a-za-z0-9-\\+]+(\\.[_a-za-z0-9-]+)*@"                 + "[a-za-z0-9-]+(\\.[a-za-z0-9]+)*(\\.[a-za-z]{2,})$";  @override protected void oncreate(bundle savedinstancestate) {     // todo auto-generated method stub     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_createcontact);      // getting path of image show     bundle extras = this.getintent().getextras();     recognizedtext = extras.getstring("text");     texttouse = recognizedtext;      // getting language used text recognition     mfromlang = extras.getstring("lang");     mcurrentlang = mfromlang;     //log.i(tag, mfromlang);      texttouse = emailvalidator();     setupui(); }  public string emailvalidator() {      string email = texttouse;      pattern pattern = pattern.compile(email_pattern);     matcher matcher = pattern.matcher(email);      if (matcher.find()) {         return email.substring(matcher.start(), matcher.end());      } else {         // todo handle condition when input doesn't have email address     }      return email;  }  public boolean validate(final string hex) {      matcher = pattern.matcher(hex);     return matcher.matches();  }  public void setupui(){      // setting textbox      medittext1 = (edittext)findviewbyid(r.id.emailet);     medittext2 = (edittext)findviewbyid(r.id.role);     medittext1.settext(texttouse);     medittext2.settext(texttouse);  } 

}

what trying is:

  1. receive text output class (already done)
  2. pass entire text output emailvalidator() (not sure if did correctly)
  3. take output emailvalidator() , pass setupui() (not done)

can me check on part did go wrong? passing of methods, or error in regex method (emailvalidator())?

currently when testing on device, page straight away display entire text output edittext.

you can check email validation here. change code below

protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate); setcontentview(r.layout.activity_createcontact);    medittext1 = (edittext)findviewbyid(r.id.emailet); medittext2 = (edittext)findviewbyid(r.id.role); bundle extras = this.getintent().getextras(); if (extras != null) { recognizedtext = extras.getstring("text"); mfromlang = extras.getstring("lang"); texttouse = recognizedtext;   mcurrentlang = mfromlang;    // texttouse = emailvalidator(texttouse);  if(isvalidemail(recognizedtext)) { texttouse=recognizedtext     } else { //this invalid email part }  setupui();       }   public final static boolean isvalidemail(charsequence target) { if (textutils.isempty(target)) { return false; } else { return android.util.patterns.email_address.matcher(target).matches(); } }    public void setupui(){      medittext1.settext(texttouse);  medittext2.settext(texttouse);  } 

Comments