45

I'm experiencing this problem randomly in the last month:

java.lang.IllegalArgumentException: parameter must be a descendant of this view
   at android.view.ViewGroup.offsetRectBetweenParentAndChild(ViewGroup.java:4479)
   at android.view.ViewGroup.offsetDescendantRectToMyCoords(ViewGroup.java:4416)
   at android.view.ViewRootImpl.scrollToRectOrFocus(ViewRootImpl.java:2656)
   at android.view.ViewRootImpl.draw(ViewRootImpl.java:2300)
   at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2249)
   at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1882)
   at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1009)
   at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5508)
   at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
   at android.view.Choreographer.doCallbacks(Choreographer.java:562)
   at android.view.Choreographer.doFrame(Choreographer.java:532)
   at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
   at android.os.Handler.handleCallback(Handler.java:730)
   at android.os.Handler.dispatchMessage(Handler.java:92)
   at android.os.Looper.loop(Looper.java:213)
   at android.app.ActivityThread.main(ActivityThread.java:5225)
   at java.lang.reflect.Method.invokeNative(Method.java)
   at java.lang.reflect.Method.invoke(Method.java:525)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:741)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
   at dalvik.system.NativeStart.main(NativeStart.java)

After a lot of digging and tests, I figured out that the problem was introduced on October 27th after updating the Appcompat lib (android-support-v7-appcompat). Latest version of Appcompat doesn't seem to solve this issue.

I suppose that the problem is not related to similar bugs (like this question) because I've isolated the commit which introduced the problem on my repo and it is the one containing the Appcompat's update.

Any clue on this? Anyone with the same problem out there?

Community
  • 1
  • 1
bonnyz
  • 13,458
  • 5
  • 46
  • 70
  • 1
    "I suppose that the problem is not related to similar bugs (like this question) because..."-- Could be true, but you will make more progress by making an educated guess about where your own code triggers the exception, and posting that information. The stack trace is useful only to a Google/AOSP developer who could patch the appcompat library. – x-code Jan 13 '15 at 19:27
  • The problem is that there's no way to reproduce the bug systematically. I really don't know the possible entry point, that's way I'm asking for suggestions or similar experience by other developers – bonnyz Jan 13 '15 at 19:41
  • 2
    Probably related http://stackoverflow.com/questions/7100555/preventing-catching-illegalargumentexception-parameter-must-be-a-descendant-of – Jeffrey Mixon Jan 19 '15 at 06:06
  • @MurtazaHussain There's no specific XML layout, this happens randomly in random sections of the app without any reference to my layout elements. – bonnyz Jan 20 '15 at 15:43
  • 1
    You probably found a solution but FWIW. This exception can get thrown if a focused view such as EditText is scrolled off the screen. It doesn't happen with all versions of Android. I ran into this with 4.4.2, 4.4.4 versions. – Bruce Apr 17 '15 at 17:09
  • @Bruce I am facing the same issue in some lollipop devices, i am having edit text in action bar and tabs with listview as i scroll to some extent it crashes.what is the fix for this ? please help me. – user2056563 May 20 '15 at 18:43
  • @bonnyz I am facing the same issue , what is the fix for this ? please help me – user2056563 May 20 '15 at 18:44
  • I resolved the issue by installing a scroll listener then clear the focused EditText as was in my case. – Bruce May 06 '16 at 23:01

3 Answers3

2

You should try the following in XML:

android:descendantFocusability="beforeDescendants"
Angel Politis
  • 10,955
  • 14
  • 48
  • 66
gauravp
  • 21
  • 2
1

usually on ListView there is method named offsetRectBetweenParentAndChild() that has the job of recycling views on scroll and this method usually throws this exception.

the best answer to this question is

Append a ScrollListener to your Activity, when listView start scrolling, clear current focus.

which I found in this question.

please check it out and let me know if there is other issues.

Pouya Danesh
  • 1,557
  • 2
  • 19
  • 36
0

Have you tried setting Focusability on your View correctly?:

mYourView.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);

or in XML

android:descendantFocusability="blocksDescendants" 
Joel
  • 838
  • 5
  • 12