为什么我的应用程序崩溃,错误消息java.lang.IllegalStateException:

时间:2019-03-15 10:16:59

标签: android developer-console

一些用户有一个特定的错误,但是我真的不明白该错误消息,开发者控制台正在向我发送。我可以在代码中看到错误发生的位置(包,行等)。

此错误似乎没有出现,所以我有点困惑,因为我无法在设备上重新创建问题。

错误消息:

java.lang.IllegalStateException: 
at android.widget.RelativeLayout$DependencyGraph.getSortedViews 
(RelativeLayout.java:1786)
at android.widget.RelativeLayout.sortChildren (RelativeLayout.java:381)
at android.widget.RelativeLayout.onMeasure (RelativeLayout.java:389)
at android.view.View.measure (View.java:23297)
at android.widget.ScrollView.measureChildWithMargins (ScrollView.java:2226)
at android.widget.FrameLayout.onMeasure (FrameLayout.java:185)
at android.widget.ScrollView.onMeasure (ScrollView.java:566)
at android.view.View.measure (View.java:23297)
at android.widget.RelativeLayout.measureChildHorizontal 
(RelativeLayout.java:715)
at android.widget.RelativeLayout.onMeasure (RelativeLayout.java:461)
at android.view.View.measure (View.java:23297)
at android.support.v4.widget.DrawerLayout.onMeasure (DrawerLayout.java:1059)
at android.view.View.measure (View.java:23297)
at android.view.ViewGroup.measureChildWithMargins (ViewGroup.java:6928)
at android.widget.FrameLayout.onMeasure (FrameLayout.java:185)
at android.view.View.measure (View.java:23297)
at android.support.v4.widget.DrawerLayout.onMeasure (DrawerLayout.java:1059)
at android.view.View.measure (View.java:23297)
at android.view.ViewGroup.measureChildWithMargins (ViewGroup.java:6928)
at android.widget.FrameLayout.onMeasure (FrameLayout.java:185)
at android.support.v7.widget.ContentFrameLayout.onMeasure 
(ContentFrameLayout.java:141)
at android.view.View.measure (View.java:23297)
at android.view.ViewGroup.measureChildWithMargins (ViewGroup.java:6928)
at android.widget.LinearLayout.measureChildBeforeLayout 
(LinearLayout.java:1514)
at android.widget.LinearLayout.measureVertical (LinearLayout.java:806)
at android.widget.LinearLayout.onMeasure (LinearLayout.java:685)
at android.view.View.measure (View.java:23297)
at android.view.ViewGroup.measureChildWithMargins (ViewGroup.java:6928)
at android.widget.FrameLayout.onMeasure (FrameLayout.java:185)
at android.view.View.measure (View.java:23297)
at android.view.ViewGroup.measureChildWithMargins (ViewGroup.java:6928)
at android.widget.LinearLayout.measureChildBeforeLayout 
(LinearLayout.java:1514)
at android.widget.LinearLayout.measureVertical (LinearLayout.java:806)
at android.widget.LinearLayout.onMeasure (LinearLayout.java:685)
at android.view.View.measure (View.java:23297)
at android.view.ViewGroup.measureChildWithMargins (ViewGroup.java:6928)
at android.widget.FrameLayout.onMeasure (FrameLayout.java:185)
at com.android.internal.policy.DecorView.onMeasure (DecorView.java:899)
at android.view.View.measure (View.java:23297)
at android.view.ViewRootImpl.performMeasure (ViewRootImpl.java:2881)
at android.view.ViewRootImpl.measureHierarchy (ViewRootImpl.java:1911)
at android.view.ViewRootImpl.performTraversals (ViewRootImpl.java:2166)
at android.view.ViewRootImpl.doTraversal (ViewRootImpl.java:1780)
at android.view.ViewRootImpl$TraversalRunnable.run (ViewRootImpl.java:7827)
at android.view.Choreographer$CallbackRecord.run (Choreographer.java:911)
at android.view.Choreographer.doCallbacks (Choreographer.java:723)
at android.view.Choreographer.doFrame (Choreographer.java:658)
at android.view.Choreographer$FrameDisplayEventReceiver.run 
(Choreographer.java:897)
at android.os.Handler.handleCallback (Handler.java:789)
at android.os.Handler.dispatchMessage (Handler.java:98)
at android.os.Looper.loop (Looper.java:164)
at android.app.ActivityThread.main (ActivityThread.java:6944)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run (Zygote.java:327)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1374)

也许有人可以给我解决这个问题的方法。

谢谢

1 个答案:

答案 0 :(得分:0)

基于相对布局的source code,您具有循环依赖关系。除非我们看到您的xml代码以及您以编程方式添加的任何视图,否则我们将无能为力

     /**
     * Builds a sorted list of views. The sorting order depends on the dependencies
     * between the view. For instance, if view C needs view A to be processed first
     * and view A needs view B to be processed first, the dependency graph
     * is: B -> A -> C. The sorted array will contain views B, A and C in this order.
     *
     * @param sorted The sorted list of views. The length of this array must
     *        be equal to getChildCount().
     * @param rules The list of rules to take into account.
     */
    void getSortedViews(View[] sorted, int... rules) {
        final ArrayDeque<Node> roots = findRoots(rules);
        int index = 0;

        Node node;
        while ((node = roots.pollLast()) != null) {
            final View view = node.view;
            final int key = view.getId();

            sorted[index++] = view;

            final ArrayMap<Node, DependencyGraph> dependents = node.dependents;
            final int count = dependents.size();
            for (int i = 0; i < count; i++) {
                final Node dependent = dependents.keyAt(i);
                final SparseArray<Node> dependencies = dependent.dependencies;

                dependencies.remove(key);
                if (dependencies.size() == 0) {
                    roots.add(dependent);
                }
            }
        }

        if (index < sorted.length) {
            throw new IllegalStateException("Circular dependencies cannot exist"
                    + " in RelativeLayout");
        }
    }