diff --git a/OsmAnd-java/src/main/java/net/osmand/map/TileSourceManager.java b/OsmAnd-java/src/main/java/net/osmand/map/TileSourceManager.java index 41f0097f6e..7632bea59f 100644 --- a/OsmAnd-java/src/main/java/net/osmand/map/TileSourceManager.java +++ b/OsmAnd-java/src/main/java/net/osmand/map/TileSourceManager.java @@ -550,7 +550,11 @@ public class TileSourceManager { private static String findOneTile(File dir) { if (dir.isDirectory()) { - for (File file : dir.listFiles()) { + File[] files = dir.listFiles(); + if (files == null) { + return null; + } + for (File file : files) { if (file.isDirectory()) { String ext = findOneTile(file); if (ext != null) { diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashFavoritesFragment.java b/OsmAnd/src/net/osmand/plus/dashboard/DashFavoritesFragment.java index 0eda59117b..c94601a05c 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashFavoritesFragment.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashFavoritesFragment.java @@ -16,6 +16,7 @@ import net.osmand.data.LatLon; import net.osmand.data.PointDescription; import net.osmand.plus.FavouritesDbHelper; import net.osmand.plus.FavouritesDbHelper.FavoritesListener; +import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.base.FavoriteImageDrawable; @@ -94,8 +95,11 @@ public class DashFavoritesFragment extends DashLocationFragment { public void setupFavorites() { View mainView = getView(); - final FavouritesDbHelper helper = getMyApplication().getFavorites(); - points = new ArrayList(helper.getFavouritePoints()); + OsmandApplication app = getMyApplication(); + if (mainView == null || app == null) { + return; + } + points = new ArrayList(app.getFavorites().getFavouritePoints()); if (points.size() == 0) { (mainView.findViewById(R.id.main_fav)).setVisibility(View.GONE); return; diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java b/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java index a43c7f7ce9..fd778cfb2a 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java @@ -71,11 +71,9 @@ import org.apache.commons.logging.Log; import java.io.File; import java.lang.ref.WeakReference; -import java.text.MessageFormat; import java.util.ArrayList; import java.util.HashSet; import java.util.List; -import java.util.Locale; import java.util.Set; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -833,15 +831,18 @@ public class DownloadActivity extends AbstractDownloadActivity implements Downlo .setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { - OsmandApplication app = (OsmandApplication) getActivity().getApplication(); - app.getSettings().setMapLocationToShow( - regionCenter.getLatitude(), - regionCenter.getLongitude(), - 5, - new PointDescription(PointDescription.POINT_TYPE_WORLD_REGION_SHOW_ON_MAP, "")); + FragmentActivity activity = getActivity(); + if (activity != null && regionCenter != null) { + OsmandApplication app = (OsmandApplication) activity.getApplication(); + app.getSettings().setMapLocationToShow( + regionCenter.getLatitude(), + regionCenter.getLongitude(), + 5, + new PointDescription(PointDescription.POINT_TYPE_WORLD_REGION_SHOW_ON_MAP, "")); - dismiss(); - MapActivity.launchMapActivityMoveToTop(getActivity()); + dismiss(); + MapActivity.launchMapActivityMoveToTop(activity); + } } }); diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementEditingContext.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementEditingContext.java index 945887616d..e753bdfda2 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementEditingContext.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementEditingContext.java @@ -1,12 +1,13 @@ package net.osmand.plus.measurementtool; +import android.support.annotation.Nullable; import android.util.Pair; +import net.osmand.GPXUtilities.TrkSegment; +import net.osmand.GPXUtilities.WptPt; import net.osmand.Location; import net.osmand.data.LatLon; import net.osmand.plus.ApplicationMode; -import net.osmand.GPXUtilities.TrkSegment; -import net.osmand.GPXUtilities.WptPt; import net.osmand.plus.OsmandApplication; import net.osmand.plus.measurementtool.command.MeasurementCommandManager; import net.osmand.plus.routing.RouteCalculationParams; @@ -212,14 +213,17 @@ public class MeasurementEditingContext { snapToRoadPairsToCalculate.clear(); findPointsToCalculate(Arrays.asList(before.points, after.points)); RoutingHelper routingHelper = application.getRoutingHelper(); - if (!snapToRoadPairsToCalculate.isEmpty() && progressListener != null && !routingHelper.isRouteBeingCalculated()) { - routingHelper.startRouteCalculationThread(getParams(), true, true); - application.runInUIThread(new Runnable() { - @Override - public void run() { - progressListener.showProgressBar(); - } - }); + if (progressListener != null && !routingHelper.isRouteBeingCalculated()) { + RouteCalculationParams params = getParams(); + if (params != null) { + routingHelper.startRouteCalculationThread(params, true, true); + application.runInUIThread(new Runnable() { + @Override + public void run() { + progressListener.showProgressBar(); + } + }); + } } } @@ -270,9 +274,12 @@ public class MeasurementEditingContext { } } + @Nullable private RouteCalculationParams getParams() { final Pair currentPair = snapToRoadPairsToCalculate.poll(); - + if (currentPair == null) { + return null; + } Location start = new Location(""); start.setLatitude(currentPair.first.getLatitude()); start.setLongitude(currentPair.first.getLongitude()); @@ -341,8 +348,9 @@ public class MeasurementEditingContext { progressListener.refresh(); } }); - if (!snapToRoadPairsToCalculate.isEmpty()) { - application.getRoutingHelper().startRouteCalculationThread(getParams(), true, true); + RouteCalculationParams params = getParams(); + if (params != null) { + application.getRoutingHelper().startRouteCalculationThread(params, true, true); } else { application.runInUIThread(new Runnable() { @Override diff --git a/OsmAnd/src/net/osmand/plus/settings/DataStorageFragment.java b/OsmAnd/src/net/osmand/plus/settings/DataStorageFragment.java index dd4ef57b7c..4415163b38 100644 --- a/OsmAnd/src/net/osmand/plus/settings/DataStorageFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/DataStorageFragment.java @@ -454,7 +454,7 @@ public class DataStorageFragment extends BaseSettingsFragment implements DataSto } protected void reloadData() { - new ReloadData(activity, getMyApplication()).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null); + new ReloadData(activity, app).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null); } @Override