From 44e7bf18df27f156f1f80982174ed54063198784 Mon Sep 17 00:00:00 2001 From: androiddevkotlin <64539346+androiddevkotlin@users.noreply.github.com> Date: Mon, 15 Mar 2021 00:25:33 +0200 Subject: [PATCH] IndexOutOfBoundsException java.lang.IndexOutOfBoundsException: Index: 3, Size: 2 at java.util.ArrayList.get(ArrayList.java:437) at net.osmand.plus.routepreparationmenu.cards.TrackEditCard.updateContent(TrackEditCard.java:92) --- .../cards/TrackEditCard.java | 41 ++++++++++--------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/TrackEditCard.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/TrackEditCard.java index e924b46aba..5f396eb71c 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/TrackEditCard.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/TrackEditCard.java @@ -82,25 +82,28 @@ public class TrackEditCard extends BaseCard { } GpxUiHelper.updateGpxInfoView(view, title, gpxInfo, dataItem, false, app); - if (gpxFile.getNonEmptySegmentsCount() > 1 && routeParams != null && routeParams.getSelectedSegment() != -1) { - TextView distanceView = view.findViewById(R.id.distance); - TextView timeView = view.findViewById(R.id.time); - ImageView timeIcon = view.findViewById(R.id.time_icon); - AndroidUiHelper.updateVisibility(view.findViewById(R.id.points_icon), false); - AndroidUiHelper.updateVisibility(view.findViewById(R.id.points_count), false); - List segments = gpxFile.getNonEmptyTrkSegments(false); - GPXUtilities.TrkSegment segment = segments.get(routeParams.getSelectedSegment()); - double distance = TrackSelectSegmentAdapter.getDistance(segment); - long time = TrackSelectSegmentAdapter.getSegmentTime(segment); - boolean timeAvailable = time != 1; - if (timeAvailable) { - timeView.setText(Algorithms.formatDuration((int) (time / 1000), - app.accessibilityEnabled())); - } - AndroidUiHelper.updateVisibility(timeView, timeAvailable); - AndroidUiHelper.updateVisibility(timeIcon, timeAvailable); - distanceView.setText(OsmAndFormatter.getFormattedDistance((float) distance, app)); - } + if (gpxFile.getNonEmptySegmentsCount() > 1) + if (routeParams != null) + if (routeParams.getSelectedSegment() != -1) + if (gpxFile.getNonEmptySegmentsCount() > routeParams.getSelectedSegment()) { + TextView distanceView = view.findViewById(R.id.distance); + TextView timeView = view.findViewById(R.id.time); + ImageView timeIcon = view.findViewById(R.id.time_icon); + AndroidUiHelper.updateVisibility(view.findViewById(R.id.points_icon), false); + AndroidUiHelper.updateVisibility(view.findViewById(R.id.points_count), false); + List segments = gpxFile.getNonEmptyTrkSegments(false); + GPXUtilities.TrkSegment segment = segments.get(routeParams.getSelectedSegment()); + double distance = TrackSelectSegmentAdapter.getDistance(segment); + long time = TrackSelectSegmentAdapter.getSegmentTime(segment); + boolean timeAvailable = time != 1; + if (timeAvailable) { + timeView.setText(Algorithms.formatDuration((int) (time / 1000), + app.accessibilityEnabled())); + } + AndroidUiHelper.updateVisibility(timeView, timeAvailable); + AndroidUiHelper.updateVisibility(timeIcon, timeAvailable); + distanceView.setText(OsmAndFormatter.getFormattedDistance((float) distance, app)); + } ImageButton editButton = view.findViewById(R.id.show_on_map); editButton.setVisibility(View.VISIBLE);