From 996ce859fd00c9d71adb862954ddabc06b50776c Mon Sep 17 00:00:00 2001 From: nuclearfog Date: Thu, 13 Jan 2022 23:36:32 +0100 Subject: [PATCH] fixed crash when uploading tweet --- .../nuclearfog/twidda/backend/TweetUpdater.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/org/nuclearfog/twidda/backend/TweetUpdater.java b/app/src/main/java/org/nuclearfog/twidda/backend/TweetUpdater.java index b8e049ee..0fd3b0a6 100644 --- a/app/src/main/java/org/nuclearfog/twidda/backend/TweetUpdater.java +++ b/app/src/main/java/org/nuclearfog/twidda/backend/TweetUpdater.java @@ -40,14 +40,18 @@ public class TweetUpdater extends AsyncTask { @Override protected Boolean doInBackground(Void[] v) { try { + long[] mediaIds = {}; String[] mimeTypes = tweet.getMimeTypes(); InputStream[] mediaStreams = tweet.getMediaStreams(); - - // upload media first - long[] mediaIds = new long[mediaStreams.length]; - for (int pos = 0 ; pos < mediaStreams.length ; pos++) { - mediaIds[pos] = twitter.uploadMedia(mediaStreams[pos], mimeTypes[pos]); - mediaStreams[pos].close(); + if (mimeTypes != null && mediaStreams !=null) { + // upload media first + mediaIds = new long[mediaStreams.length]; + for (int pos = 0; pos < mediaStreams.length; pos++) { + // upload media file and save media ID + mediaIds[pos] = twitter.uploadMedia(mediaStreams[pos], mimeTypes[pos]); + // close stream after upload + mediaStreams[pos].close(); + } } // upload tweet