Fixed null pointer exceptions

This commit is contained in:
Denis 2014-07-23 18:40:13 +04:00
parent 0f953adef1
commit 921f457e8c
6 changed files with 40 additions and 23 deletions

View file

@ -225,7 +225,9 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
}
public void hideProgressBar() {
getSherlockActivity().setSupportProgressBarIndeterminateVisibility(false);
if (getSherlockActivity() != null){
getSherlockActivity().setSupportProgressBarIndeterminateVisibility(false);
}
}
private void updateSelectionMode(ActionMode m) {
@ -963,7 +965,9 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
@Override
protected void onPostExecute(Void result) {
getSherlockActivity().setProgressBarIndeterminateVisibility(false);
if (getSherlockActivity() != null){
getSherlockActivity().setProgressBarIndeterminateVisibility(false);
}
if (info.gpx != null){
getMyApplication().getSelectedGpxHelper().selectGpxFile(info.gpx, selected, true);
listAdapter.notifyDataSetChanged();

View file

@ -274,7 +274,7 @@ public class SearchAddressFragment extends SherlockFragment {
String city = settings.getLastSearchedCityName();
String cityName = !Algorithms.isEmpty(postcode) ? postcode : city;
ai.objectName = settings.getLastSearchedStreet();
ai.historyName = MessageFormat.format(ctx. getString(R.string.search_history_int_streets), settings.getLastSearchedStreet(),
ai.historyName = MessageFormat.format(ctx != null ? ctx.getString(R.string.search_history_int_streets) : "", settings.getLastSearchedStreet(),
settings.getLastSearchedIntersectedStreet(), cityName);
ai.zoom = 17;
return ai;
@ -287,7 +287,7 @@ public class SearchAddressFragment extends SherlockFragment {
String cityName = !Algorithms.isEmpty(postcode) ? postcode : city;
String street = settings.getLastSearchedStreet();
ai.objectName = street;
ai.historyName = MessageFormat.format(ctx.getString(R.string.search_history_street), street, cityName);
ai.historyName = MessageFormat.format(ctx != null ? ctx.getString(R.string.search_history_street) : "", street, cityName);
ai.zoom = 16;
return ai;
}
@ -301,7 +301,7 @@ public class SearchAddressFragment extends SherlockFragment {
String street = settings.getLastSearchedStreet();
String building = settings.getLastSearchedBuilding();
ai.objectName = street + " " + building;
ai.historyName = MessageFormat.format(ctx.getString(R.string.search_history_building), building, street,
ai.historyName = MessageFormat.format(ctx != null ? ctx.getString(R.string.search_history_building) : "", building, street,
cityName);
ai.zoom = 17;
return ai;
@ -310,7 +310,7 @@ public class SearchAddressFragment extends SherlockFragment {
public static AddressInformation buildCity(Context ctx, OsmandSettings settings){
AddressInformation ai = new AddressInformation();
String city = settings.getLastSearchedCityName();
ai.historyName = MessageFormat.format(ctx.getString(R.string.search_history_city), city);
ai.historyName = MessageFormat.format(ctx != null ? ctx.getString(R.string.search_history_city) : "", city);
ai.objectName = city;
ai.zoom = 14;
return ai;

View file

@ -439,7 +439,7 @@ public class SearchTransportFragment extends SherlockFragment implements SearchA
}
public LatLon getEndStop(int position){
if(position == -1){
if(position < 0){
return lastKnownMapLocation;
}
RouteInfoLocation item = intermediateListAdapater.getItem(position);

View file

@ -255,7 +255,7 @@ public class GpxImportHelper {
private String saveImport(final GPXUtilities.GPXFile gpxFile, final String fileName) {
final String warning;
if (gpxFile.isEmpty()) {
if (gpxFile.isEmpty() || fileName == null) {
warning = application.getString(R.string.error_reading_gpx);
} else {
final File importDir = application.getAppPath(IndexConstants.GPX_IMPORT_DIR);

View file

@ -167,17 +167,23 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
header = getLayoutInflater().inflate(R.layout.osmo_groups_list_header, null);
getExpandableListView().addHeaderView(header);
CompoundButton trackr = (CompoundButton) header.findViewById(R.id.enable_tracker);
trackr.setChecked(osMoPlugin.getTracker().isEnabledTracker());
if(osMoPlugin != null && osMoPlugin.getTracker() != null){
trackr.setChecked(osMoPlugin.getTracker().isEnabledTracker());
}
trackr.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked) {
osMoPlugin.getTracker().enableTracker();
if (osMoPlugin != null && osMoPlugin.getTracker() != null){
osMoPlugin.getTracker().enableTracker();
}
app.startNavigationService(NavigationService.USED_BY_LIVE);
app.getSettings().SERVICE_OFF_INTERVAL.set(0);
} else {
osMoPlugin.getTracker().disableTracker();
if (osMoPlugin != null && osMoPlugin.getTracker() != null){
osMoPlugin.getTracker().disableTracker();
}
if (app.getNavigationService() != null) {
app.getNavigationService().stopIfNeeded(app,NavigationService.USED_BY_LIVE);
}
@ -449,8 +455,10 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
if(device != null) {
Location location = device.getLastLocation();
MapActivity.getMapViewTrackingUtilities().setMapLinkedToLocation(false);
app.getSettings().setMapLocationToShow(location.getLatitude(), location.getLongitude(), app.getSettings().getLastKnownMapZoom(),
null, device.getVisibleName(), device);
if (location != null){
app.getSettings().setMapLocationToShow(location.getLatitude(), location.getLongitude(), app.getSettings().getLastKnownMapZoom(),
null, device.getVisibleName(), device);
}
OsMoPositionLayer.setFollowTrackerId(device);
MapActivity.launchMapActivityMoveToTop(OsMoGroupsActivity.this);
}
@ -496,17 +504,19 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
Builder bld = new AlertDialog.Builder(this);
bld.setTitle(R.string.osmo_group);
StringBuilder sb = new StringBuilder();
setFields(sb, R.string.osmo_group_name, group.name);
if(group.description != null) {
setFields(sb, R.string.osmo_group_description, group.description);
if (group != null){
setFields(sb, R.string.osmo_group_name, group.name);
if(group.description != null) {
setFields(sb, R.string.osmo_group_description, group.description);
}
if(group.expireTime != 0) {
setFields(sb, R.string.osmo_expire_group, new Date(group.expireTime).toString());
}
if(group.policy != null) {
setFields(sb, R.string.osmo_group_policy, group.policy);
}
setFields(sb, R.string.osmo_connect_to_group_id, group.groupId);
}
if(group.expireTime != 0) {
setFields(sb, R.string.osmo_expire_group, new Date(group.expireTime).toString());
}
if(group.policy != null) {
setFields(sb, R.string.osmo_group_policy, group.policy);
}
setFields(sb, R.string.osmo_connect_to_group_id, group.groupId);
ScrollView sv = new ScrollView(this);
TextView tv = new TextView(this);
sv.addView(tv);

View file

@ -54,6 +54,9 @@ public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLa
try {
for (int i = 0; i < objects.size(); i++) {
TransportStop n = objects.get(i);
if (n.getLocation() == null){
return;
}
int x = (int) tb.getPixXFromLatLon(n.getLocation().getLatitude(), n.getLocation().getLongitude());
int y = (int) tb.getPixYFromLatLon(n.getLocation().getLatitude(), n.getLocation().getLongitude());
if (Math.abs(x - ex) <= radius && Math.abs(y - ey) <= radius) {