java.lang.StackOverFlow 错误。怀疑浏览量太多?
当你遇到如下错误(Android 1.5)时,是因为嵌套的ViewGroup太多,还是因为View总数太大?有没有什么技巧可以绕过这个问题,同时仍然保持应用程序的相同外观?
java.lang.StackOverflowError
at android.text.Styled.measureText(Styled.java:371)
at android.text.Layout.measureText(Layout.java:1600)
at android.text.Layout.getLineMax(Layout.java:654)
at android.text.Layout.draw(Layout.java:310)
at android.text.BoringLayout.draw(BoringLayout.java:356)
at android.widget.TextView.onDraw(TextView.java:3921)
at android.view.View.draw(View.java:5838)
at android.view.ViewGroup.drawChild(ViewGroup.java:1486)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1228)
at android.view.ViewGroup.drawChild(ViewGroup.java:1484)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1228)
at android.widget.AbsListView.dispatchDraw(AbsListView.java:1319)
at android.widget.ListView.dispatchDraw(ListView.java:2820)
at android.view.View.draw(View.java:5944)
at android.widget.AbsListView.draw(AbsListView.java:2121)
at android.view.ViewGroup.drawChild(ViewGroup.java:1486)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1228)
at android.view.ViewGroup.drawChild(ViewGroup.java:1484)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1228)
at android.view.View.draw(View.java:5841)
at android.widget.FrameLayout.draw(FrameLayout.java:352)
at android.view.ViewGroup.drawChild(ViewGroup.java:1486)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1228)
at android.view.ViewGroup.drawChild(ViewGroup.java:1484)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1228)
at android.view.View.draw(View.java:5841)
at android.widget.FrameLayout.draw(FrameLayout.java:352)
at android.view.ViewGroup.drawChild(ViewGroup.java:1486)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1228)
at android.view.View.draw(View.java:5841)
at android.view.ViewGroup.drawChild(ViewGroup.java:1486)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1228)
at android.view.View.draw(View.java:5841)
at android.view.ViewGroup.drawChild(ViewGroup.java:1486)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1228)
at android.view.View.draw(View.java:5841)
at android.widget.FrameLayout.draw(FrameLayout.java:352)
at android.view.ViewGroup.drawChild(ViewGroup.java:1486)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1228)
at android.view.ViewGroup.drawChild(ViewGroup.java:1484)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1228)
at android.view.ViewGroup.drawChild(ViewGroup.java:1484)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1228)
at android.view.View.draw(View.java:5841)
at android.widget.FrameLayout.draw(FrameLayout.java:352)
at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1847)
at android.view.ViewRoot.draw(ViewRoot.java:1217)
at android.view.ViewRoot.performTraversals(ViewRoot.java:1030)
at android.view.ViewRoot.handleMessage(ViewRoot.java:1482)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3948)
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:782)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
at dalvik.system.NativeStart.main(Native Method)
When you get an error like the one below (Android 1.5), is it because there are too many nested ViewGroups, or because the total number of Views is too great? Are there any tricks to get around it while still keeping the same look to your app?
java.lang.StackOverflowError
at android.text.Styled.measureText(Styled.java:371)
at android.text.Layout.measureText(Layout.java:1600)
at android.text.Layout.getLineMax(Layout.java:654)
at android.text.Layout.draw(Layout.java:310)
at android.text.BoringLayout.draw(BoringLayout.java:356)
at android.widget.TextView.onDraw(TextView.java:3921)
at android.view.View.draw(View.java:5838)
at android.view.ViewGroup.drawChild(ViewGroup.java:1486)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1228)
at android.view.ViewGroup.drawChild(ViewGroup.java:1484)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1228)
at android.widget.AbsListView.dispatchDraw(AbsListView.java:1319)
at android.widget.ListView.dispatchDraw(ListView.java:2820)
at android.view.View.draw(View.java:5944)
at android.widget.AbsListView.draw(AbsListView.java:2121)
at android.view.ViewGroup.drawChild(ViewGroup.java:1486)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1228)
at android.view.ViewGroup.drawChild(ViewGroup.java:1484)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1228)
at android.view.View.draw(View.java:5841)
at android.widget.FrameLayout.draw(FrameLayout.java:352)
at android.view.ViewGroup.drawChild(ViewGroup.java:1486)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1228)
at android.view.ViewGroup.drawChild(ViewGroup.java:1484)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1228)
at android.view.View.draw(View.java:5841)
at android.widget.FrameLayout.draw(FrameLayout.java:352)
at android.view.ViewGroup.drawChild(ViewGroup.java:1486)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1228)
at android.view.View.draw(View.java:5841)
at android.view.ViewGroup.drawChild(ViewGroup.java:1486)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1228)
at android.view.View.draw(View.java:5841)
at android.view.ViewGroup.drawChild(ViewGroup.java:1486)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1228)
at android.view.View.draw(View.java:5841)
at android.widget.FrameLayout.draw(FrameLayout.java:352)
at android.view.ViewGroup.drawChild(ViewGroup.java:1486)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1228)
at android.view.ViewGroup.drawChild(ViewGroup.java:1484)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1228)
at android.view.ViewGroup.drawChild(ViewGroup.java:1484)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1228)
at android.view.View.draw(View.java:5841)
at android.widget.FrameLayout.draw(FrameLayout.java:352)
at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1847)
at android.view.ViewRoot.draw(ViewRoot.java:1217)
at android.view.ViewRoot.performTraversals(ViewRoot.java:1030)
at android.view.ViewRoot.handleMessage(ViewRoot.java:1482)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3948)
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:782)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
at dalvik.system.NativeStart.main(Native Method)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
你有太多的嵌套布局。您可以查看 d.android.com 上的官方 Android 博客,获取有关如何优化布局的提示和技巧。
You have (way) too many nested layouts. You can check out the official Android blog at d.android.com to get tips and tricks on how to optimize layouts.
就我而言,我解决了
in my case I resolved by in
就我而言,这是由使用 v4 支持和 HoloEverywhere v1.4 库的另一个片段内的片段视图分页器内的列表中的嵌套布局(复杂列表 itens)引起的。
我必须删除嵌套的片段并以不同的方式构建它。
In my case it was caused by nested layouts (complex list itens) in a list inside a fragment view pager inside another fragment, using v4 support and HoloEverywhere v1.4 libraries.
I had to remove nested fragments and build it in a different way.
就我而言,
自定义列表视图具有相对布局,然后它释放了 Stackoverflowerror。
如果您的
listview
有相对布局,则将其删除:DIn my case,
Customized list view has Relative Layout, then it released
Stackoverflowerror
.If your
listview
has relative layout, then erase it :D就我而言,这是
ScrollView
内的ListView
,当我尝试将其滚动到底部时。它会产生堆栈溢出错误。因此,避免将
ListView
放在ScrollView
中。或者我们可以使用不同的方法来实现ListView。
滚动视图内的 Android 列表视图
In my case that was
ListView
inside aScrollView
and when I try to Scroll it to the bottom. It produces stackoverflow error.So, avoid to have
ListView
insideScrollView
.Or we can use different approach to implement ListView.
Android list view inside a scroll view
就我而言,在 XamarinForms 中,我通过将
CachingStrategy="RecycleElement"
添加到我的ListView
并删除额外的布局来解决此错误。Android 用户应该使用
RecyclerView
或其他视图回收方法。In my case and in XamarinForms, I solved this error by adding
CachingStrategy="RecycleElement"
to myListView
and also removing extra layouts.Android users should use
RecyclerView
or other view recycling methods.对于我们案例中的 Xamarin Forms,使用 ListViews 并没有解决问题,异常在我们拥有的轮播上不断引发,并且我们无法从另一个线程调用绘制方法,因为我们需要的一些用 NControl 绘制的图形不允许我们使用这样做(我猜与OpenGL相关)。因此,最终只需在我们的轮播自定义渲染器中捕获异常并对其调用 Invalidate() 即可解决问题。
For Xamarin Forms in our case using ListViews didn't resolve the issue, the exception kept raising on a carousel we have, and we can't call the draw method from another thread because some graphics painted with NControl we need doesn't allow us to do that (OpenGL related I guess). So in the end just catching the exception in our carousel custom renderer and calling Invalidate() on it resolved the problem.