Home » Android » java – Android Studio LogCat won't always output fields within a loop-Exceptionshub

java – Android Studio LogCat won't always output fields within a loop-Exceptionshub

Posted by: admin February 26, 2020 Leave a comment

Questions:

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 ?

How to&Answers:

Solved : Adding an incremented field, in this case an index for each instruction causes the Logcat to print in ‘each’ case