From b077081d2f438d1e4c723746f9ae6c590b9f8252 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sat, 27 Aug 2011 12:57:06 +0200 Subject: [PATCH] Fix NPE --- .../plus/activities/LocalIndexesActivity.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/LocalIndexesActivity.java b/OsmAnd/src/net/osmand/plus/activities/LocalIndexesActivity.java index a50c7eef70..31c8ce423a 100644 --- a/OsmAnd/src/net/osmand/plus/activities/LocalIndexesActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/LocalIndexesActivity.java @@ -10,7 +10,6 @@ import java.util.Map; import java.util.Set; import net.osmand.Algoritms; -import net.osmand.FavouritePoint; import net.osmand.IProgress; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; @@ -35,7 +34,6 @@ import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; -import android.view.Window; import android.view.ContextMenu.ContextMenuInfo; import android.view.View.OnClickListener; import android.widget.BaseExpandableListAdapter; @@ -44,7 +42,6 @@ import android.widget.CheckBox; import android.widget.ExpandableListView; import android.widget.TextView; import android.widget.Toast; -import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.ExpandableListView.ExpandableListContextMenuInfo; public class LocalIndexesActivity extends ExpandableListActivity { @@ -84,16 +81,19 @@ public class LocalIndexesActivity extends ExpandableListActivity { @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { long packedPos = ((ExpandableListContextMenuInfo)menuInfo).packedPosition; - - final LocalIndexInfo point = (LocalIndexInfo) listAdapter.getChild(ExpandableListView.getPackedPositionGroup(packedPos), - ExpandableListView.getPackedPositionChild(packedPos)); - if(point.getGpxFile() != null){ - Location loc = point.getGpxFile().findFistLocation(); - if(loc != null){ - OsmandSettings.getOsmandSettings(LocalIndexesActivity.this).setMapLocationToShow(loc.getLatitude(),loc.getLongitude()); + int group = ExpandableListView.getPackedPositionGroup(packedPos); + int child = ExpandableListView.getPackedPositionChild(packedPos); + if (child >= 0 && group >= 0) { + final LocalIndexInfo point = (LocalIndexInfo) listAdapter.getChild(group, child); + if (point != null && point.getGpxFile() != null) { + Location loc = point.getGpxFile().findFistLocation(); + if (loc != null) { + OsmandSettings.getOsmandSettings(LocalIndexesActivity.this).setMapLocationToShow(loc.getLatitude(), + loc.getLongitude()); + } + ((OsmandApplication) getApplication()).setGpxFileToDisplay(point.getGpxFile()); + MapActivity.launchMapActivityMoveToTop(LocalIndexesActivity.this); } - ((OsmandApplication) getApplication()).setGpxFileToDisplay(point.getGpxFile()); - MapActivity.launchMapActivityMoveToTop(LocalIndexesActivity.this); } } });