fix null pointer error when cannot open a sd card file

This commit is contained in:
Jimmy Shih
2012-11-02 12:47:41 -07:00
parent 4b09254789
commit 214be6b802
2 changed files with 5 additions and 7 deletions
@@ -132,7 +132,7 @@ public class SaveActivity extends Activity {
}) })
.setTitle(success ? R.string.generic_success_title : R.string.generic_error_title); .setTitle(success ? R.string.generic_success_title : R.string.generic_error_title);
if (success && trackId != -1L && !playTrack) { if (success && trackId != -1L && !playTrack && savedPath != null) {
builder.setNegativeButton( builder.setNegativeButton(
R.string.share_track_share_file, new DialogInterface.OnClickListener() { R.string.share_track_share_file, new DialogInterface.OnClickListener() {
@Override @Override
@@ -191,7 +191,7 @@ public class SaveActivity extends Activity {
* To be invoked after showing the result dialog. * To be invoked after showing the result dialog.
*/ */
private void onPostResultDialog() { private void onPostResultDialog() {
if (success && playTrack) { if (success && playTrack && savedPath != null) {
Intent intent = new Intent() Intent intent = new Intent()
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK) .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK)
.putExtra(GOOGLE_EARTH_TOUR_FEATURE_ID, KmlTrackWriter.TOUR_FEATURE_ID) .putExtra(GOOGLE_EARTH_TOUR_FEATURE_ID, KmlTrackWriter.TOUR_FEATURE_ID)
@@ -79,7 +79,7 @@ class TrackWriterImpl implements TrackWriter {
@Override @Override
public String getAbsolutePath() { public String getAbsolutePath() {
return file.getAbsolutePath(); return file == null ? null : file.getAbsolutePath();
} }
private void writeTrackAsync() { private void writeTrackAsync() {
@@ -112,10 +112,8 @@ class TrackWriterImpl implements TrackWriter {
writeDocument(); writeDocument();
} catch (InterruptedException e) { } catch (InterruptedException e) {
Log.i(Constants.TAG, "The track write was interrupted"); Log.i(Constants.TAG, "The track write was interrupted");
if (file != null) { if (file != null && !file.delete()) {
if (!file.delete()) { Log.w(TAG, "Failed to delete file " + file.getAbsolutePath());
Log.w(TAG, "Failed to delete file " + file.getAbsolutePath());
}
} }
success = false; success = false;
errorMessage = R.string.external_storage_canceled; errorMessage = R.string.external_storage_canceled;