Java's replace method not working -


i trying replace routename , routedurationinminutes rpelace method not working. working when had outside run function inside not work. ideas? have added code trying run. im sorry , forth. tried shorten make easier others read.

the value g =  {"routes":[{"routename":"i-190 n; electric ave","routedurationinminutes":70,"routelengthkm":83.865,"routelengthmiles":52.111278915,"toll":false},{"routename":"i-190 n; greenville rd","routedurationinminutes":82,"routelengthkm":92.569,"routelengthmiles":57.519692099000004,"toll":false}],"startpoint":"street address","endpoint":"destination","startlatitude":"42.20115054203528","startlongitude":"-71.85038140607858","endlatitude":"42.201220801535","endlongitude":"-71.849075146695"}   final runnable rundatapoll = new runnable() {          @override         public void run() {             string g;             try {                 g = new apicall().execute().get().getbody().tostring();                 system.out.println(g);                 string route1;                  string route2;                 string time1;                 string time2;                 string time3;                 arraylist parse= new arraylist();                 arraylist route= new arraylist();                 arraylist time= new arraylist();                 pattern p= pattern.compile("routename?.+?routelengthkm");                 matcher m = p.matcher(g);                 pattern p2= pattern.compile("routename?.+?routedurationinminutes");                 pattern p3= pattern.compile("routedurationinminutes?.+?routelengthkm");                 matcher m3= p3.matcher(g);                  while (m.find()) {                     parse.add(m.group());                 }                  while (m3.find()){                     time.add(m3.group());                 }                  int l=0;                 while (l<parse.size()){                     matcher m2 =p2.matcher((charsequence) parse.get(l));                      while(m2.find()){                         route.add(m2.group());                     }                      l++;                 }  //////////////////////////////////////////////////////////////////////////////////////                   route1= (string) route.get(0);                 route2= (string) route.get(1);                 route1= route1.replace(",routedurationinminutes","");                 route1= route1.replace("routename:","");                 route2= route2.replace(",routedurationinminutes","");                 route2= route2.replace("routename:","");                 time1= (string) time.get(0);                 time2= (string) time.get(1);                 time1= time1.replace("routedurationinminutes:","");                 time1= time1.replace(",routelengthkm","");                 time2= time2.replace("routedurationinminutes:","");                 time2= time2.replace(",routelengthkm","");                   t1.setvalue(time1);                 t2.setvalue(time2);                 r1.setvalue(route1);                 r2.setvalue(route2);              } catch (interruptedexception e) {                 e.printstacktrace();             } catch (executionexception e) {                 e.printstacktrace();             }          }     };  >>>routename":"i-190 n; electric ave","routedurationinminutes 

looks thread might not being executed suggested in comments.

this worked me:

package example;  public class example {       final string g="routename:i-190 n; electric ave,routedurationinminutes";      final runnable rundatapoll = new runnable() {             @override             public void run() {                   string route1=g;                   system.out.println("before thread");                   system.out.println(route1);                   route1= route1.replace(",routedurationinminutes","");                   route1= route1.replace("routename:","");                   system.out.println("after running thread:");                   system.out.println(route1);                   system.out.println("done");             }     };      public static void main(string[] args) {         example example = new example();         thread thread = new thread(example.rundatapoll);         thread.start();     }  } 

output:

before thread routename:i-190 n; electric ave,routedurationinminutes after running thread: i-190 n; electric ave done 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -