Android: Crash when switching to grid view

Created on 11 Nov 2018  Â·  23Comments  Â·  Source: nextcloud/android

Actual behaviour

Switching to grid view in any folder crashes the app. The folder cannot be opened without crash after that.

Expected behaviour

Switch to grid view and don't crash.

Steps to reproduce

  1. Go to any folder.
  2. Select grid view.

Similar issues

It looks like similar issues were reported before (#2471, #2668). But there is no solution other than reinstalling the app.

Environment data

Android version:
8.1.0
Nextcloud app version:
3.3.2

Logs

FATAL EXCEPTION: main
Process: com.nextcloud.client, PID: 32059
java.lang.ArrayIndexOutOfBoundsException: length=0; index=0
    at android.support.v7.widget.GridLayoutManager.calculateItemBorders(GridLayoutManager.java:324)
    at android.support.v7.widget.GridLayoutManager.calculateItemBorders(GridLayoutManager.java:309)
    at android.support.v7.widget.GridLayoutManager.updateMeasurements(GridLayoutManager.java:280)
    at android.support.v7.widget.GridLayoutManager.onAnchorReady(GridLayoutManager.java:355)
    at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:581)
    at android.support.v7.widget.GridLayoutManager.onLayoutChildren(GridLayoutManager.java:170)
    at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3812)
    at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3529)
    at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:4082)
    at android.view.View.layout(View.java:19659)
    at android.view.ViewGroup.layout(ViewGroup.java:6075)
    at android.support.v4.widget.SwipeRefreshLayout.onLayout(SwipeRefreshLayout.java:606)
    at android.view.View.layout(View.java:19659)
    at android.view.ViewGroup.layout(ViewGroup.java:6075)
    at android.support.design.widget.CoordinatorLayout.layoutChild(CoordinatorLayout.java:1191)
    at android.support.design.widget.CoordinatorLayout.onLayoutChild(CoordinatorLayout.java:876)
    at android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:895)
    at android.view.View.layout(View.java:19659)
    at android.view.ViewGroup.layout(ViewGroup.java:6075)
    at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1083)
    at android.view.View.layout(View.java:19659)
    at android.view.ViewGroup.layout(ViewGroup.java:6075)
    at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
    at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
    at android.view.View.layout(View.java:19659)
    at android.view.ViewGroup.layout(ViewGroup.java:6075)
    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1791)
    at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1780)
    at android.widget.LinearLayout.onLayout(LinearLayout.java:1546)
    at android.view.View.layout(View.java:19659)
    at android.view.ViewGroup.layout(ViewGroup.java:6075)
    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1791)
    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1635)
    at android.widget.LinearLayout.onLayout(LinearLayout.java:1544)
    at android.view.View.layout(View.java:19659)
    at android.view.ViewGroup.layout(ViewGroup.java:6075)
    at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1171)
    at android.view.View.layout(View.java:19659)
    at android.view.ViewGroup.layout(ViewGroup.java:6075)
    at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
    at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
    at android.view.View.layout(View.java:19659)
    at android.view.ViewGroup.layout(ViewGroup.java:6075)
    at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
    at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
    at android.view.View.layout(View.java:19659)
    at android.view.ViewGroup.layout(ViewGroup.java:6075)
    at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
    at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
    at android.view.View.layout(View.java:19659)
    at android.view.ViewGroup.layout(ViewGroup.java:6075)
    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1791)
    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1635)
    at android.widget.LinearLayout.onLayout(LinearLayout.java:1544)
    at android.view.View.layout(View.java:19659)
    at android.view.ViewGroup.layout(ViewGroup.java:6075)
    at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
    at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
    at com.android.internal.policy.DecorView.onLayout(DecorView.java:761)
approved bug pr exists

Most helpful comment

Thanks for finding the issue, @zroug
I created a fix and it will be in next version.

All 23 comments

GitMate.io thinks possibly related issues are https://github.com/nextcloud/android/issues/2668 (App crash when switching to grid view), https://github.com/nextcloud/android/issues/491 (Upload view crash when playing with flight mode), https://github.com/nextcloud/android/issues/81 (Grid view > back while folder is loading crashes app), https://github.com/nextcloud/android/issues/2756 (NPE for file details on master for images), and https://github.com/nextcloud/android/issues/90 (Crash on deleting three local+remote files with latestF-Droid beta release(20160621)).

Thank you for your detailed report with crash log.
Unfortunately this crash does not contain anything from our app, so it is hard to understand why it is crashing.
Is this also happening on a freshly created empty folder in "/" (root)?
Maybe you find a longer logcat output?

Yes, this crash also happens when I create a new folder named "test" in "/" and switch to grid view. The app also crashes when I restart it, delete the folder and recreate it. It then crashes immediately, I don't even have to switch to grid view.

When I clear the currentLog.txt file and then immediately create the folder "test" (the app crashing in the process) no log file is created at all.

Immediately before the exception is thrown, there is this entry in Logcat:

duplicate layer name: changing com.nextcloud.client/com.owncloud.android.ui.activity.FileDisplayActivity to com.nextcloud.client/com.owncloud.android.ui.activity.FileDisplayActivity#1

Here is a little bit more output from logcat, that shows the moments before crash.

D OperationsService: Starting command with id 2
D OwnCloudClient #2: REQUEST MKCOL /remote.php/webdav/Test/
W StaticLayout: maxLineHeight should not be -1.  maxLines:1 lineCount:1
W StaticLayout: maxLineHeight should not be -1.  maxLines:1 lineCount:1
D CreateRemoteFolderOperation: Create directory /Test/: Operation finished with HTTP status code 201 (success)
D OwnCloudClient #2: REQUEST PROPFIND /remote.php/webdav/Test/
I ReadRemoteFolderOperation: Synchronized /Test/: Operation finished with HTTP status code 207 (success)
D CreateFolderOperation: Create directory /Test/ in Database
D FileActivity: Received result of operation in FileActivity - common behaviour for all the FileActivities 
D OperationsService: Called 1 listeners
D FileActivity: dismiss loading dialog
D OperationsService: Stopping after command with id 2
D AndroidRuntime: Shutting down VM
--------- beginning of crash
E AndroidRuntime: FATAL EXCEPTION: main
E AndroidRuntime: Process: com.nextcloud.client, PID: 4571
E AndroidRuntime: java.lang.ArrayIndexOutOfBoundsException: length=0; index=0

I have looked into the source of GridLayoutManager and I think this exception can only be raised if the value spanCount of the GridLayoutManager is -1. The default value of it happens to be -1 and setSpanCount prevents you from setting it to a value that is less than 1. So it looks like the issue is that setSpanCount was never called. setSpanCount sets the number of columns/rows in the layout.

Edit: I have investigated a bit further and have noticed that setSpanCount is always called in the constructor. But there is an early return if the new spanCount equals the existing spanCount. That means the constructor was called with a spanCount of -1.

I have found the issue and a workaround. The wrong spanCount origins from this value:

https://github.com/nextcloud/android/blob/5aba8fe28a4d6b7682ef0bb4e1f9a4cdff9f1345/src/main/java/com/owncloud/android/ui/fragment/ExtendedListFragment.java#L137

I think the only place where it gets set unchecked is here:

https://github.com/nextcloud/android/blob/5aba8fe28a4d6b7682ef0bb4e1f9a4cdff9f1345/src/main/java/com/owncloud/android/ui/fragment/ExtendedListFragment.java#L486

Looking into my com.nextcloud.client_preferences.xml showed that somehow my grid_columns was saved as -1.0. Changing it to 2.0 solved the issue for me.

I suggest to add a check when loading this value as a workaround for users that have this issue. And maybe someone who is familiar with the codebase can find out how the wrong value got there in the first place.

This request did not receive an update in the last 4 weeks. Please take a look again and update the issue with new details, otherwise the issue will be automatically closed in 2 weeks. Thank you!

This request did not receive an update in the last 4 weeks. Please take a look again and update the issue with new details, otherwise the issue will be automatically closed in 2 weeks. Thank you!

I think this bug is still present. https://github.com/nextcloud/android/issues/3255#issuecomment-481701130 should contain all information that are necessary to fix it.

I have exactly the same problem, the crash looks the same:

05-16 22:12:34.944  8119  8119 D AndroidRuntime: Shutting down VM
05-16 22:12:34.946  8119  8119 E AndroidRuntime: FATAL EXCEPTION: main
05-16 22:12:34.946  8119  8119 E AndroidRuntime: Process: com.nextcloud.client, PID: 8119
05-16 22:12:34.946  8119  8119 E AndroidRuntime: java.lang.ArrayIndexOutOfBoundsException: length=0; index=0
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at androidx.recyclerview.widget.GridLayoutManager.calculateItemBorders(GridLayoutManager.java:325)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at androidx.recyclerview.widget.GridLayoutManager.calculateItemBorders(GridLayoutManager.java:310)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at androidx.recyclerview.widget.GridLayoutManager.updateMeasurements(GridLayoutManager.java:281)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at androidx.recyclerview.widget.GridLayoutManager.onAnchorReady(GridLayoutManager.java:356)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at androidx.recyclerview.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:579)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at androidx.recyclerview.widget.GridLayoutManager.onLayoutChildren(GridLayoutManager.java:171)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3924)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at androidx.recyclerview.widget.RecyclerView.dispatchLayout(RecyclerView.java:3641)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at androidx.recyclerview.widget.RecyclerView.onLayout(RecyclerView.java:4194)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at android.view.View.layout(View.java:20672)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at android.view.ViewGroup.layout(ViewGroup.java:6194)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at androidx.swiperefreshlayout.widget.SwipeRefreshLayout.onLayout(SwipeRefreshLayout.java:625)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at android.view.View.layout(View.java:20672)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at android.view.ViewGroup.layout(ViewGroup.java:6194)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at androidx.coordinatorlayout.widget.CoordinatorLayout.layoutChild(CoordinatorLayout.java:1183)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at androidx.coordinatorlayout.widget.CoordinatorLayout.onLayoutChild(CoordinatorLayout.java:870)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at androidx.coordinatorlayout.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:889)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at android.view.View.layout(View.java:20672)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at android.view.ViewGroup.layout(ViewGroup.java:6194)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1083)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at android.view.View.layout(View.java:20672)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at android.view.ViewGroup.layout(ViewGroup.java:6194)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at android.view.View.layout(View.java:20672)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at android.view.ViewGroup.layout(ViewGroup.java:6194)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1812)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1801)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at android.widget.LinearLayout.onLayout(LinearLayout.java:1567)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at android.view.View.layout(View.java:20672)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at android.view.ViewGroup.layout(ViewGroup.java:6194)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1812)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1656)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at android.widget.LinearLayout.onLayout(LinearLayout.java:1565)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at android.view.View.layout(View.java:20672)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at android.view.ViewGroup.layout(ViewGroup.java:6194)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at androidx.drawerlayout.widget.DrawerLayout.onLayout(DrawerLayout.java:1231)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at android.view.View.layout(View.java:20672)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at android.view.ViewGroup.layout(ViewGroup.java:6194)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at android.view.View.layout(View.java:20672)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at android.view.ViewGroup.layout(ViewGroup.java:6194)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at android.view.View.layout(View.java:20672)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at android.view.ViewGroup.layout(ViewGroup.java:6194)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at android.view.View.layout(View.java:20672)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at android.view.ViewGroup.layout(ViewGroup.java:6194)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1812)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1656)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at android.widget.LinearLayout.onLayout(LinearLayout.java:1565)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at android.view.View.layout(View.java:20672)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at android.view.ViewGroup.layout(ViewGroup.java:6194)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at com.android.internal.policy.DecorView.onLayout(DecorView.java:753)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at android.view.View.layout(View.java:20672)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at android.view.ViewGroup.layout(ViewGroup.java:6194)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2799)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2316)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1463)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7190)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:949)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at android.view.Choreographer.doCallbacks(Choreographer.java:761)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at android.view.Choreographer.doFrame(Choreographer.java:696)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:935)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at android.os.Handler.handleCallback(Handler.java:873)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at android.os.Handler.dispatchMessage(Handler.java:99)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at android.os.Looper.loop(Looper.java:193)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at android.app.ActivityThread.main(ActivityThread.java:6718)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at java.lang.reflect.Method.invoke(Native Method)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
05-16 22:12:34.946  8119  8119 E AndroidRuntime:        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
05-16 22:12:34.948  1175  3496 W ActivityManager:   Force finishing activity com.nextcloud.client/com.owncloud.android.ui.activity.FileDisplayActivity

I can confirm that my com.nextcloud.client_preferences.xml had grid_columns set to -1, too, and changing it to 2 fixed the problem immediately.

Very well done bug trace @zroug!

This request did not receive an update in the last 4 weeks. Please take a look again and update the issue with new details, otherwise the issue will be automatically closed in 2 weeks. Thank you!

Still an issue, presumably just had this yesterday on another phone (didn't trace the logs after crash while switching to grid view though, but looks like exactly the same issue).

This request did not receive an update in the last 4 weeks. Please take a look again and update the issue with new details, otherwise the issue will be automatically closed in 2 weeks. Thank you!

Still relevant.

Hm.
From above log (thanks for that) it seems that this is purely Android specific code.

Do you see something common on these crashes? E.g. big folders, only files, only images, etc.…?

I can confirm that my com.nextcloud.client_preferences.xml had grid_columns set to -1, too, and changing it to 2 fixed the problem immediately.

Ah. I overread this part…
-1 is the default value.

If it is -1, we use AUTO_FIT:
https://github.com/nextcloud/android/blob/6643b6c8397a5792e963fa3641d29f45a7b73af6/src/main/java/com/owncloud/android/ui/fragment/ExtendedListFragment.java#L436-L440

I fear that this somehow kills it… on certain devices…

This request did not receive an update in the last 4 weeks. Please take a look again and update the issue with new details, otherwise the issue will be automatically closed in 2 weeks. Thank you!

Still relevant, I have a phone with this issue at the moment (but didn't bother to fix it manually yet by editing the xml by hand)

This request did not receive an update in the last 4 weeks. Please take a look again and update the issue with new details, otherwise the issue will be automatically closed in 2 weeks. Thank you!

Still relevant.

This request did not receive an update in the last 4 weeks. Please take a look again and update the issue with new details, otherwise the issue will be automatically closed in 2 weeks. Thank you!

Still relevant.

Thanks for finding the issue, @zroug
I created a fix and it will be in next version.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

toobie83 picture toobie83  Â·  3Comments

ezaquarii picture ezaquarii  Â·  3Comments

JSoko picture JSoko  Â·  3Comments

eppfel picture eppfel  Â·  3Comments

AndyScherzinger picture AndyScherzinger  Â·  3Comments