Another java.lang.IllegalArgumentException: parameter must be a descendant of this view

…衆ロ難τιáo~ 提交于 2019-12-20 14:23:43

问题


Users are getting the following exception in my app on certain phones. I tried reproducing the error myself but couldn't . I searched through stack overflow for similar problems and tried their solutions but none seem to be working.

Here are the answers I already tried:

  1. Preventing/catching "IllegalArgumentException: parameter must be a descendant of this view" error
  2. java.lang.IllegalArgumentException: parameter must be a descendant of this view Error
  3. Setting the following attribute: android:windowSoftInputMode="stateHidden|adjustPan"

I have an edittext but it's outside of the expandablelistview.

I am trying to find an explanation on why this is happening and what might cause it to happen. I apologize but I can't post any code.

java.lang.IllegalArgumentException: parameter must be a descendant of this view at android.view.ViewGroup.offsetRectBetweenParentAndChild(ViewGroup.java:4568) at android.view.ViewGroup.offsetDescendantRectToMyCoords(ViewGroup.java:4505) at android.view.ViewGroup$ViewLocationHolder.init(ViewGroup.java:6743) at android.view.ViewGroup$ViewLocationHolder.obtain(ViewGroup.java:6680) at android.view.ViewGroup$ChildListForAccessibility.init(ViewGroup.java:6638) at android.view.ViewGroup$ChildListForAccessibility.obtain(ViewGroup.java:6606) at android.view.ViewGroup.addChildrenForAccessibility(ViewGroup.java:1697) at android.view.ViewGroup.onInitializeAccessibilityNodeInfoInternal(ViewGroup.java:2525) at android.view.View.onInitializeAccessibilityNodeInfo(View.java:5213) at android.widget.AdapterView.onInitializeAccessibilityNodeInfo(AdapterView.java:946) at android.widget.AbsListView.onInitializeAccessibilityNodeInfo(AbsListView.java:1449) at android.widget.ListView.onInitializeAccessibilityNodeInfo(ListView.java:3781) at android.widget.ExpandableListView.onInitializeAccessibilityNodeInfo(ExpandableListView.java:1348) at android.view.View.createAccessibilityNodeInfoInternal(View.java:5174) at android.view.View.createAccessibilityNodeInfo(View.java:5161) at android.view.AccessibilityInteractionController$AccessibilityNodePrefetcher.prefetchDescendantsOfRealNode(AccessibilityInteractionController.java:811) at android.view.AccessibilityInteractionController$AccessibilityNodePrefetcher.prefetchDescendantsOfRealNode(AccessibilityInteractionController.java:834) at android.view.AccessibilityInteractionController$AccessibilityNodePrefetcher.prefetchDescendantsOfRealNode(AccessibilityInteractionController.java:834) at android.view.AccessibilityInteractionController$AccessibilityNodePrefetcher.prefetchAccessibilityNodeInfos(AccessibilityInteractionController.java:720) at android.view.AccessibilityInteractionController.findAccessibilityNodeInfoByAccessibilityIdUiThread(AccessibilityInteractionController.java:147) at android.view.AccessibilityInteractionController.access$300(AccessibilityInteractionController.java:49) at android.view.AccessibilityInteractionController$PrivateHandler.handleMessage(AccessibilityInteractionController.java:971) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5097) at java.lang.reflect.Method.invokeNative(Method.java) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) at dalvik.system.NativeStart.main(NativeStart.java)


回答1:


The problem was caused by adding a wrongly inflated header to two different listviews.

I inflated a view using listViewA as the parent and adding it to listViewB also. As such:

RelativeLayout listViewHeader = (RelativeLayout) inflater.inflate(R.layout.listviewheader, listViewA, false);

// Set some views

listViewA.addHeaderView(listViewHeader);
listViewB.addHeaderView(listViewHeader);

I fixed it by changing the above to the following:

RelativeLayout listViewHeaderA = (RelativeLayout) inflater.inflate(R.layout.listviewheader, listViewA, false);
RelativeLayout listViewHeaderB = (RelativeLayout) inflater.inflate(R.layout.listviewheader, listViewB, false);

listViewA.addHeaderView(listViewHeaderA);
listViewB.addHeaderView(listViewHeaderB);

As for reproducing the crash, the problem happened when Google Talk Back is turned on. Here is my take on the situation: Google Talk Back does text to speech on views that are in focus (either by touch or auto-focused). When it enters a screen with multiple views requesting focus, it reads the views according to a hierarchy/order.

If you have a layout (parent) with three views (children), Google Talk Back checks how the views are arranged and then reads them accordingly. For example, in a layout with three textview lined up horizontally, Google Talk Back may read the left textview first, then the middle one, then the one on the right.

In my case, I was inflating a header view with listViewA as the parent and adding that view to both listViewA and listViewB. When listViewBgains focus and Google Talk Back tries to interpret its children, it sees the header view is not a child of the list and throws the exception. This also happens if I inflate the header view with no parents (null).




回答2:


I have append on scroll listener in ScrollView and solve problem

 lst_payment_info.setOnScrollListener(new AbsListView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
            if (SCROLL_STATE_TOUCH_SCROLL == scrollState) {
                View currentFocus = getCurrentFocus();
                if (currentFocus != null) {
                    currentFocus.clearFocus();
                }
            }
        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {

        }
    });



回答3:


I was also getting the same error when Google TalkBack is turned on. In my case, I was inflating a view with the boolean attachToParent true.So by making it false worked for me.



来源:https://stackoverflow.com/questions/30585561/another-java-lang-illegalargumentexception-parameter-must-be-a-descendant-of-th

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!