如何使用有限 logcat 调试(这个?)StackOverflowError?
How to debug (this?) StackOverflowError with a finite logcat?
很抱歉,如果这是宽泛的、不合适的或欺骗的,请随时举报。
但是我找不到解决办法。我得到 WhosebugError
,并且 Android 工作室显示 -
08-03 16:22:49.293 5163-5163/com.package E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.WhosebugError
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5384)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(V
我现在花了几个小时试图了解问题所在:我不知道我的代码中有任何递归调用。我在问:
- 对于可能导致这个特定问题的原因,您有什么建议吗?
- 对于如何在技术上面对类似问题,您有什么建议吗?有什么方法可以找到堆栈中的 "root" 原因?应该有一些递归的东西在进行,但它肯定有(a)一个起点,以及对那个点的调用; (b) 结束,当抛出
WhosebugError
时。我们可以看到结束部分,但看不到开始,因为 logcat 停止了。
我今天在处理片段时遇到了这个问题。此代码足以导致错误:
public static class ProductionFragment extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.something, container);
return view;
}
}
解决方案是以下之一:
//The preferred way
View view = inflater.inflate(R.layout.something, container, false);
//Not optimal but still working way
View view = inflater.inflate(R.layout.something, null);
当我用两个参数调用 inflater.inflate()
方法时,充气器隐式地尝试将充气视图附加到容器。这会导致新创建的视图已经附加到片段,即使我们仍然没有 return 我们的视图。
如果我们将 null 作为第二个参数传递,Android Studio 会提醒我们
When inflating a layout, avoid passing in null as the parent view,
since otherwise any layout parameters on the root of the inflated
layout will be ignored.
技术上驱使我们填充第二个参数。
管理它的最佳方法是通过将容器参数传递给函数而不是将我们的视图添加到根来跟踪容器参数。这是通过使用三个参数调用 inflate
来完成的:
inflater.inflate(R.layout.something, container, false);
最后一个 false
告诉 inflate
方法不要将视图添加到我们提供的容器视图中。
那么,为了防止将来出现这种错误,如何以编程方式决定 inflate
方法使用的重载?
您是否正在实施一种要求您 return 视图的方法,而视图附加不是您要完成的? (片段,ListView/Spinners 的 ListAdapter...)
使用inflater.inflate(R.layout.something, container, false);
你是从代码构建你的界面,你加载的是容器吗?
使用inflater.inflate(R.layout.something, null);
您是否正在充气您打算手动添加到另一个容器的东西?
使用 inflater.inflate(R.layout.something, container);
并且不要将项目添加到容器中(它已经这样做了)。
很抱歉,如果这是宽泛的、不合适的或欺骗的,请随时举报。
但是我找不到解决办法。我得到 WhosebugError
,并且 Android 工作室显示 -
08-03 16:22:49.293 5163-5163/com.package E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.WhosebugError
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5384)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(V
我现在花了几个小时试图了解问题所在:我不知道我的代码中有任何递归调用。我在问:
- 对于可能导致这个特定问题的原因,您有什么建议吗?
- 对于如何在技术上面对类似问题,您有什么建议吗?有什么方法可以找到堆栈中的 "root" 原因?应该有一些递归的东西在进行,但它肯定有(a)一个起点,以及对那个点的调用; (b) 结束,当抛出
WhosebugError
时。我们可以看到结束部分,但看不到开始,因为 logcat 停止了。
我今天在处理片段时遇到了这个问题。此代码足以导致错误:
public static class ProductionFragment extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.something, container);
return view;
}
}
解决方案是以下之一:
//The preferred way
View view = inflater.inflate(R.layout.something, container, false);
//Not optimal but still working way
View view = inflater.inflate(R.layout.something, null);
当我用两个参数调用 inflater.inflate()
方法时,充气器隐式地尝试将充气视图附加到容器。这会导致新创建的视图已经附加到片段,即使我们仍然没有 return 我们的视图。
如果我们将 null 作为第二个参数传递,Android Studio 会提醒我们
When inflating a layout, avoid passing in null as the parent view, since otherwise any layout parameters on the root of the inflated layout will be ignored.
技术上驱使我们填充第二个参数。
管理它的最佳方法是通过将容器参数传递给函数而不是将我们的视图添加到根来跟踪容器参数。这是通过使用三个参数调用 inflate
来完成的:
inflater.inflate(R.layout.something, container, false);
最后一个 false
告诉 inflate
方法不要将视图添加到我们提供的容器视图中。
那么,为了防止将来出现这种错误,如何以编程方式决定 inflate
方法使用的重载?
您是否正在实施一种要求您 return 视图的方法,而视图附加不是您要完成的? (片段,ListView/Spinners 的 ListAdapter...)
使用
inflater.inflate(R.layout.something, container, false);
你是从代码构建你的界面,你加载的是容器吗?
使用
inflater.inflate(R.layout.something, null);
您是否正在充气您打算手动添加到另一个容器的东西?
使用
inflater.inflate(R.layout.something, container);
并且不要将项目添加到容器中(它已经这样做了)。