0

I was looking through my exception log from users and found this common exception:

java.lang.IllegalArgumentException: parameter must be a descendant of this view
   at android.view.ViewGroup.offsetRectBetweenParentAndChild(ViewGroup.java:2521)
   at android.view.FocusFinder.findNearestTouchable(FocusFinder.java:411)
   at android.view.ViewRoot.handleMessage(ViewRoot.java:1746)
   at android.os.Handler.dispatchMessage(Handler.java:99)
   at android.os.Looper.loop(Looper.java:123)
   at android.app.ActivityThread.main(ActivityThread.java:4363)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:521)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
   at dalvik.system.NativeStart.main(Native Method)

Is there some way I can gracefully handle this exception and prevent a Force Close? I can't reproduce the problem.

I found this Google thread about it being a problem with Donut (1.5) and it was fixed. But I'm getting this from users using later versions of Android. My min API is to 1.6 and targeted at 2.2.

Bryan Denny
  • 27,363
  • 32
  • 109
  • 125
  • Any indication of what (in your code) is causing it? – Squonk May 09 '11 at 02:13
  • @MistSquonk Not that I'm aware. The stacktrace isn't pointing to any part of my code. My guess is it might be the (Safe)ViewFlipper I'm using? – Bryan Denny May 09 '11 at 02:16
  • Backtrace shows a handler involved. Are posting any event to Handler?. Look like by the time message gets dispatched, the View got invalid or lost focus. – Sukumar May 09 '11 at 10:18
  • @Sukumar I'm using a ViewFlipper + Gestures to "flip" left or right to other views, so maybe they went to a new activity before it finished processing the motion event/gesture? – Bryan Denny May 09 '11 at 15:19
  • Yup, I think so. Look into the your Handler's code and check it has any references to parent View/Activity. Or try surrounding the handler's code in Exception. – Sukumar May 10 '11 at 06:16
  • If you are using ListView, try my way: http://stackoverflow.com/a/12888761/1745885 – Bruce Oct 15 '12 at 03:11

2 Answers2

0

I've just met this similar problem.

I found that what findFocus() returns, is not a child or descendant of rootView.

So, if indexOfChild() returns -1, I simply pass null as 2nd param (focused) to findNextFocus() of FocusFinder.

Sanbrother
  • 601
  • 5
  • 12
0

My guess : It could be that offsetDescendantRectToMyCoords() is trying to get the coordinates of a grand child, ie: the child it is looking for is not a direct descendant of the viewgroup caller.

David
  • 1,842
  • 2
  • 21
  • 31