From 4cd6ce1fb854da102672a26c40e7ce78dc7ca92a Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Thu, 26 Oct 2023 14:59:12 +0200 Subject: [PATCH] fix crash when trying to upload from nextcloud MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit this is just a quickfix to get the correct context. However a better way would be to avoid using a context inside viewModel. stacktrace: 303-13303 AndroidRuntime com.nextcloud.talk2 E FATAL EXCEPTION: main Process: com.nextcloud.talk2, PID: 13303 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.nextcloud.talk2/com.nextcloud.talk.remotefilebrowser.activities.RemoteFileBrowserActivity}: android.content.res.Resources$NotFoundException: String resource ID #0x7f1301f3 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3311) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3460) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2047) at android.os.Handler.dispatchMessage(Handler.java:107) at android.os.Looper.loop(Looper.java:224) at android.app.ActivityThread.main(ActivityThread.java:7590) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950) Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x7f1301f3 at android.content.res.Resources.getText(Resources.java:381) at android.content.res.MiuiResources.getText(MiuiResources.java:97) at android.content.res.Resources.getString(Resources.java:474) at com.nextcloud.talk.remotefilebrowser.viewmodels.RemoteFileBrowserItemsViewModel.(RemoteFileBrowserItemsViewModel.kt:99) at com.nextcloud.talk.remotefilebrowser.viewmodels.RemoteFileBrowserItemsViewModel_Factory.newInstance(RemoteFileBrowserItemsViewModel_Factory.java:50) at com.nextcloud.talk.remotefilebrowser.viewmodels.RemoteFileBrowserItemsViewModel_Factory.get(RemoteFileBrowserItemsViewModel_Factory.java:39) at com.nextcloud.talk.remotefilebrowser.viewmodels.RemoteFileBrowserItemsViewModel_Factory.get(RemoteFileBrowserItemsViewModel_Factory.java:12) at com.nextcloud.talk.dagger.modules.ViewModelFactory.create(ViewModelModule.kt:53) at androidx.lifecycle.ViewModelProvider$Factory.create(ViewModelProvider.kt:83) at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.kt:187) at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.kt:153) at com.nextcloud.talk.remotefilebrowser.activities.RemoteFileBrowserActivity.initViewModel(RemoteFileBrowserActivity.kt:124) at com.nextcloud.talk.remotefilebrowser.activities.RemoteFileBrowserActivity.onCreate(RemoteFileBrowserActivity.kt:110) at android.app.Activity.performCreate(Activity.java:7893) at android.app.Activity.performCreate(Activity.java:7880) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3286) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3460)  at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)  at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)  at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2047)  at android.os.Handler.dispatchMessage(Handler.java:107)  at android.os.Looper.loop(Looper.java:224)  at android.app.ActivityThread.main(ActivityThread.java:7590)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)  2023-10-26 14:29:28.357 13303-13303 nextcloud.talk com.nextcloud.talk2 W Attempt to remove non-JNI local reference, dumping thread Signed-off-by: Marcel Hibbe --- .../viewmodels/RemoteFileBrowserItemsViewModel.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/remotefilebrowser/viewmodels/RemoteFileBrowserItemsViewModel.kt b/app/src/main/java/com/nextcloud/talk/remotefilebrowser/viewmodels/RemoteFileBrowserItemsViewModel.kt index 238521e27d..3b2396d9da 100644 --- a/app/src/main/java/com/nextcloud/talk/remotefilebrowser/viewmodels/RemoteFileBrowserItemsViewModel.kt +++ b/app/src/main/java/com/nextcloud/talk/remotefilebrowser/viewmodels/RemoteFileBrowserItemsViewModel.kt @@ -22,7 +22,6 @@ package com.nextcloud.talk.remotefilebrowser.viewmodels -import android.content.res.Resources import android.util.Log import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData @@ -96,7 +95,7 @@ constructor( get() = _selectedPaths init { - val key = Resources.getSystem().getString(R.string.nc_file_browser_sort_by_key) + val key = appPreferences.context.resources.getString(R.string.nc_file_browser_sort_by_key) sortingFlow = appPreferences.readString(key) CoroutineScope(Dispatchers.Main).launch { var state = appPreferences.sorting