简体   繁体   中英

Android Studio LogCat won't always output fields within a loop

I am logging the output of various parts of the route set by a Navigation app Using exactly the same route each time, 10 instruction objects are generated I log various aspects of each instruction

However, if I choose log one field, that is generally empty, it sometimes leaves out certain iterations of the loop

here is my code for log 1

Log.d("qw", "NUMBER OF INSTRUCTIONS " + resp.getInstructions().size());
for (Instruction i:resp.getInstructions()) {
    Log.d("qw", "extra " + i.getExtraInfoJSON());
}

This should log the 'extra' field 10 x it doesn't , it logs it only 6x

2020-02-19 00:48:04.045 17624-17624/com.graphhopper.android D/qw: NUMBER OF INSTRUCTIONS 10
2020-02-19 00:48:04.045 17624-17624/com.graphhopper.android D/qw: extra {heading=251.34}
2020-02-19 00:48:04.045 17624-17624/com.graphhopper.android D/qw: extra {}
2020-02-19 00:48:04.045 17624-17624/com.graphhopper.android D/qw: extra {}
2020-02-19 00:48:04.045 17624-17624/com.graphhopper.android D/qw: extra {exit_number=1, exited=true, turn_angle=1.76}
2020-02-19 00:48:04.045 17624-17624/com.graphhopper.android D/qw: extra {exit_number=1, exited=true, turn_angle=2.81}
2020-02-19 00:48:04.045 17624-17624/com.graphhopper.android D/qw: extra {last_heading=73.96885135138928}

If I now log two fields, including one that is always populated, like so

Log.d("qw", "NUMBER OF INSTRUCTIONS " + resp.getInstructions().size());
for (Instruction i: resp.getInstructions()) {

    Log.d("qw", "extra " + i.getExtraInfoJSON()); // heading | roundabout 

    Log.d("qw", "translation " + i.getTurnDescription(esTR)); // translation of 
}

now, all of the 10 instructions are logged

this is what is logged
2020-02-19 00:21:48.185 17624-17624/com.graphhopper.android D/qw: NUMBER OF INSTRUCTIONS 10
2020-02-19 00:21:48.185 17624-17624/com.graphhopper.android D/qw: extra {heading=251.34}
2020-02-19 00:21:48.185 17624-17624/com.graphhopper.android D/qw: translation continue onto Clements Crescent
2020-02-19 00:21:48.185 17624-17624/com.graphhopper.android D/qw: extra {}
2020-02-19 00:21:48.186 17624-17624/com.graphhopper.android D/qw: translation turn left onto Samuel Place
2020-02-19 00:21:48.186 17624-17624/com.graphhopper.android D/qw: extra {}
2020-02-19 00:21:48.186 17624-17624/com.graphhopper.android D/qw: translation turn right onto Herbert Road
2020-02-19 00:21:48.186 17624-17624/com.graphhopper.android D/qw: extra {}
2020-02-19 00:21:48.186 17624-17624/com.graphhopper.android D/qw: translation turn left onto Laurence Street
2020-02-19 00:21:48.186 17624-17624/com.graphhopper.android D/qw: extra {}
2020-02-19 00:21:48.186 17624-17624/com.graphhopper.android D/qw: translation turn right onto Bankwood Road
2020-02-19 00:21:48.186 17624-17624/com.graphhopper.android D/qw: extra {}
2020-02-19 00:21:48.186 17624-17624/com.graphhopper.android D/qw: translation turn left onto Comries Road
2020-02-19 00:21:48.186 17624-17624/com.graphhopper.android D/qw: extra {}
2020-02-19 00:21:48.186 17624-17624/com.graphhopper.android D/qw: translation turn right onto Bankwood Road
2020-02-19 00:21:48.186 17624-17624/com.graphhopper.android D/qw: extra {exit_number=1, exited=true, turn_angle=1.76}
2020-02-19 00:21:48.186 17624-17624/com.graphhopper.android D/qw: translation At roundabout, take exit 1 onto Clarkin Road
2020-02-19 00:21:48.186 17624-17624/com.graphhopper.android D/qw: extra {exit_number=1, exited=true, turn_angle=2.81}
2020-02-19 00:21:48.186 17624-17624/com.graphhopper.android D/qw: translation At roundabout, take exit 1 onto Clarkin Road
2020-02-19 00:21:48.186 17624-17624/com.graphhopper.android D/qw: extra {last_heading=73.96885135138928}
2020-02-19 00:21:48.186 17624-17624/com.graphhopper.android D/qw: translation arrive at destination

Why am I experiencing this behaviour ?

已解决:添加一个递增字段,在这种情况下,每条指令的索引会导致 Logcat 在“每个”情况下打印

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM