I am trying to construct a string using string.format(), but it stops working (just over) half way through.
private String constructMessage(String messageType, int messageCode,Position location) {
double lat = location.getLat();
double lon = location.getLon();
double ele = location.getEle();
double speed = 0.0;
double heading = 0.0;
String msg = "$PNGVEST," + messageType + "," + VEST_ID + ","
+ System.currentTimeMillis() + "," + lat + "," + lon + "," + ele
+ "," + speed + "," + heading + "," + messageCode;
String test = String.format("$PNGVEST,%s,%d,%d,%f,%f,%f,$f,$f,$d",
messageType, VEST_ID, System.currentTimeMillis(), lat, lon, ele,
speed, heading, messageCode);
System.out.println(msg);
System.out.println(test);
return msg;
}
When I run the above code, I get the following output:
$PNGVEST,LOCATION,1,1439998967553,51.558641765246364,-3.043043462354341,-1.0,0.0,0.0,0
$PNGVEST,LOCATION,1,1439998967553,51.558642,-3.043043,-1.000000,$f,$f,$d
$PNGVEST,LOCATION,1,1439998968553,51.55862560874394,-3.043027770590568,-1.0,0.0,0.0,0
$PNGVEST,LOCATION,1,1439998968553,51.558626,-3.043028,-1.000000,$f,$f,$d
Why does it not format the last 3 variables?