From ac3f8b9bfd3adc5c563f96c28e863fd2236e7055 Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Mon, 3 May 2021 16:52:08 +0900 Subject: [PATCH] Wrapping ViewModelProvider constructor with try-catch to prevent crashes. Addresses austinhuang0131/barinsta#903. --- .../awais/instagrabber/customviews/PostsRecyclerView.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/awais/instagrabber/customviews/PostsRecyclerView.java b/app/src/main/java/awais/instagrabber/customviews/PostsRecyclerView.java index b2456e0a..f01a5528 100644 --- a/app/src/main/java/awais/instagrabber/customviews/PostsRecyclerView.java +++ b/app/src/main/java/awais/instagrabber/customviews/PostsRecyclerView.java @@ -192,7 +192,12 @@ public class PostsRecyclerView extends RecyclerView { } private void initSelf() { - mediaViewModel = new ViewModelProvider(viewModelStoreOwner).get(MediaViewModel.class); + try { + mediaViewModel = new ViewModelProvider(viewModelStoreOwner).get(MediaViewModel.class); + } catch (Exception e) { + Log.e(TAG, "initSelf: ", e); + } + if (mediaViewModel == null) return; mediaViewModel.getList().observe(lifeCycleOwner, list -> { if (list.size() <= 0) return; feedAdapter.submitList(list, () -> {