button - email extractor android program crashes aide -


public class mainactivity extends activity {      public static linearlayout layout = null;     public static edittext urlstring = null;     public static button submit = null;     public static listview emailsfound = null;     public static arraylist<string> emaillist = new arraylist<string>();     public static arraylist<string> urllist = new arraylist<string>();     public static arrayadapter<string> adapter = null;      /**      * called when activity first created.      */     @override     public void oncreate(bundle savedinstancestate) {          super.oncreate(savedinstancestate);         layout = new linearlayout(this);         urlstring = new edittext(this);         submit = new button(this);         submit.settext("submit");         emailsfound = new listview(this);         layout.setorientation(linearlayout.vertical);         layout.addview(urlstring);         layout.addview(submit);         layout.addview(emailsfound);         setcontentview(layout);         adapter = new arrayadapter(this, android.r.layout.simple_list_item_1, emaillist);         emailsfound.setadapter(adapter);         submit.setonclicklistener(new onclicklistener() {              @override             public void onclick(view v) {                  urllist.add(urlstring.gettext().tostring());                 int = 0;                 while (true) {                     string page = getpage(urlstring.gettext().tostring());                     arraylist<string> urls = new arraylist<string>();                     urls = geturls(page);                     arraylist<string> addresses = new arraylist<string>();                     addresses = getaddresses(page);                     (int = 0; < urls.size(); i++) {                         urllist.add(urls.get(a));                     }                     (int = 0; < addresses.size(); i++) {                         emaillist.add(addresses.get(a));                     }                     removeduplicates(urllist);                     removeduplicates(emaillist);                     adapter.notifydatasetchanged();                     i++;                     urlstring.settext(urllist.get(i).tostring());                 }             }              ;         });     }      public string getpage(string url) {          if (url.tolowercase().startswith("http") == false) {             url = "http://" + url;         }         url fromstring = null;         urlconnection openconnection = null;         try {             fromstring = new url(url);             openconnection = fromstring.openconnection();             bufferedreader in = null;             url = "";             in = new bufferedreader(new inputstreamreader(openconnection.getinputstream()));             string input = "";             if (in != null) {                 while ((input = in.readline()) != null) {                     url = url + input + "\r\n";                 }                 in.close();             }         } catch (exception ex) {             ex.printstacktrace();         }         return url;     }      public arraylist<string> geturls(string page) {          arraylist<string> s = new arraylist<string>();         while (page.tolowercase().contains("<a href=\"http")) {             int = page.tolowercase().indexof("href=\"http") + "href=\"".length();             if (i > -1) {                 string s1 = page.substring(i, page.tolowercase().indexof("\"", i));                 s.add(s1);                 page = page.substring(i + "http".length());             }         }         return s;     }      public boolean validate(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();     }      public arraylist<string> getaddresses(string page) {          arraylist<string> s = new arraylist<string>();         while (page.contains("@")) {             int = page.indexof("@");             if (i > -1) {                 int beginning = page.lastindexof(" ", i);                 if (beginning > -1) {                     int ending = page.indexof(" ", i);                     if (ending > -1) {                         string address = page.substring(beginning + 1, ending - 1);                         address = address.tolowercase();                         if (address.startswith("href=\"mailto:")) {                             int b = address.indexof(":") + 1;                             address = address.substring(b);                             int e = address.indexof("\"");                             if (e > -1) {                                 if (e > address.indexof("@")) {                                     address = address.substring(0, address.indexof("\""));                                 }                                 if (address.contains("?")) {                                     address = address.substring(0, address.indexof("?"));                                 }                                 if (!address.contains("<") && !address.contains(">")) {                                     if (validate(address)) {                                         s.add(address);                                     }                                 }                             } else {                                 int b2 = address.indexof(">") + 1;                                 if (b2 > -1) {                                     if (b2 < address.indexof("@")) {                                         address = address.substring(b2);                                     }                                 }                                 int e2 = address.indexof("<");                                 if (e2 > -1) {                                     if (e2 > address.indexof("@")) {                                         address = address.substring(0, e2);                                     }                                 }                                 if (!address.contains("<") && !address.contains(">")) {                                     if (validate(address)) {                                         s.add(address);                                     }                                 }                             }                         }                     }                 }             }             page = page.substring(i + 1);         }         return s;     }      public arraylist<string> removeduplicates(arraylist<string> list) {          arraylist<string> output = new arraylist<string>();         (int = 0; < list.size(); i++) {             boolean b = false;             (int = 0; < list.size(); i++) {                 if (list.get(i).tostring().tolowercase().equals(list.get(a).tostring().tolowercase())) {                     b = true;                 }             }             if (b == false) {                 output.add(list.get(i));             }         }         return output;     } } 

this program made in aide on android netbook. crashes on button click. wondering doing wrong. tried before runnables crashed too. i'm new android development fluent in java. noticed there alot of differences between android , java.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -