计算器在Android 2.3.3设备只 [英] Stackoverflow on Android 2.3.3 Devices Only

查看:135
本文介绍了计算器在Android 2.3.3设备只的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在原生Android应用程序其中,i面临purticularly Android的一些bug 2.3.3版本及以下的Andr​​oid 3.0版本

我没有得到确切的地方我飘落在我的code,因为在code logcat的每一行编译但最后我得到很奇怪的错误描述如下日志:

  java.lang.StackOverflowError
在java.util.concurrent.locks.ReentrantLock中的$ NonfairSync.tryAcquire(ReentrantLock.java:189)
在java.util.concurrent.locks.AbstractQueuedSynchronizer.acquire(AbstractQueuedSynchronizer.java:1171)
在java.util.concurrent.locks.ReentrantLock中的$ NonfairSync.lock(ReentrantLock.java:185)
在java.util.concurrent.locks.ReentrantLock.lock(ReentrantLock.java:261)
在java.util.concurrent.CopyOnWriteArrayList.removeRange(CopyOnWriteArrayList.java:569)
在java.util.concurrent.CopyOnWriteArrayList.remove(CopyOnWriteArrayList.java:366)
在java.util.concurrent.CopyOnWriteArrayList.remove(CopyOnWriteArrayList.java:376)
在android.view.ViewTreeObserver.removeOn preDrawListener(ViewTreeObserver.java:377)

在android.widget.TextView.onDraw(TextView.java:4085)
在android.view.View.draw(View.java:6986)
在android.view.ViewGroup.drawChild(ViewGroup.java:1739)
在android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466)
在android.view.ViewGroup.drawChild(ViewGroup.java:1737)
在android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466)
在android.view.ViewGroup.drawChild(ViewGroup.java:1737)
在android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466)
在android.view.View.draw(View.java:6989)
在android.view.ViewGroup.drawChild(ViewGroup.java:1739)
在android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466)
在android.view.View.draw(View.java:6989)
在android.view.ViewGroup.drawChild(ViewGroup.java:1739)
在android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466)
在android.view.ViewGroup.drawChild(ViewGroup.java:1737)

    在android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466)
在android.view.ViewGroup.drawChild(ViewGroup.java:1737)
在android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466)
在android.view.View.draw(View.java:6989)
在android.view.ViewGroup.drawChild(ViewGroup.java:1739)
在android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466)
在android.view.View.draw(View.java:6989)
在android.view.ViewGroup.drawChild(ViewGroup.java:1739)
在android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466)
在android.view.ViewGroup.drawChild(ViewGroup.java:1737)
在android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466)
在android.view.ViewGroup.drawChild(ViewGroup.java:1737)
在android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466)
在android.view.View.draw(View.java:6989)
在android.widget.FrameLayout.draw(FrameLayout.java:361)
在android.view.ViewGroup.drawChild(ViewGroup.java:1739)
在android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466)
在android.view.ViewGroup.drawChild(ViewGroup.java:1737)
在android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466)

    在android.view.View.draw(View.java:6989)
在android.view.ViewGroup.drawChild(ViewGroup.java:1739)
在android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466)
在android.view.View.draw(View.java:6989)
在android.view.ViewGroup.drawChild(ViewGroup.java:1739)
在android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466)
在android.view.View.draw(View.java:7093)
在android.widget.FrameLayout.draw(FrameLayout.java:361)
在android.widget.ScrollView.draw(ScrollView.java:1421)
在android.view.ViewGroup.drawChild(ViewGroup.java:1739)
在android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466)
在android.view.ViewGroup.drawChild(ViewGroup.java:1737)
在android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466)
在android.view.View.draw(View.java:6989)
在android.widget.FrameLayout.draw(FrameLayout.java:361)
在android.view.ViewGroup.drawChild(ViewGroup.java:1739)
在android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466)
在android.view.ViewGroup.d
 

由于我检查我的codeI没有发现任何痕迹的计算器。当我在Android 3.0上运行相同的code或以上版本,它有效,正确的,但不能运行在Android 2.3.3及放大器;低于3.0的版本。 请让我知道,如果有任何人知道这个问题?

我用的标签活动,这样主要布局的main.xml 并在该次活动拥有视图称为的firstTab_Results.xml ,它拥有这的确进行充气最多20个意见 inflate_table_firstTab.xml 布局。

我不递归也无妨,它膨胀最多20次(inflate_table_firstTab.xml)以表格布局(firstTab_Results.xml)。

 注:#1发生在单个或双核处理器的设备及放大器;没有全屏模式。
 

解决方案

您的视图层次过深。当层次递归得出,你用完堆栈空间,不能去任何更深的层次,如堆栈跟踪观察。

为什么这只是发生在更早的设备是因为UI线程堆栈大小是Android 2.3的设备,但16kB的在以后的操作系统版本只有12KB( REF )。

如何降低视图层次结构的深度?只要避免嵌套布局,只要有可能。您发布的布局过于复杂,没点这个堆栈溢出模型内固定他们为你(这需要一些时间来正确地做,很可能过于具体,以帮助其他人),但这里有一些一般准则:

  • 删除不必要的布局。例如,在您的firsttab_results.xml,你只需要在 TableLayout RelativeLayout的的LinearLayout 顶部是pretty的无用。在你的滚动型至少有6嵌套布局,当一个或最多两个很可能是不够的。

  • 一个独生子女的布局是一个code气味。大部分时间相同,可以实现移动子向其父布局和调整用边距布局

  • 通常有没有必要把布局一个 RelativeLayout的里面。相对布局是使用相对定位和儿童基线对齐布局它的子功能强大。

  • 如果您需要嵌套布局只是一个背景,尝试移动的背景,如只是一个查看这是大小相同的嵌套布局是,铺在它之上的其他元素。

  • 讲究的Andr​​oid lint警告。该工具已成为在检测视图层次结构可以简化复杂性相当不错。

I been working on Native Android App where i face some bug on purticularly Android 2.3.3 versions and below Android 3.0 version .

I am not getting where exactly am falling in my code because in Logcat Every Line of code compiled but at the end am getting very strange error describe log below:

java.lang.StackOverflowError
at java.util.concurrent.locks.ReentrantLock$NonfairSync.tryAcquire(ReentrantLock.java:189)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquire(AbstractQueuedSynchronizer.java:1171)
at java.util.concurrent.locks.ReentrantLock$NonfairSync.lock(ReentrantLock.java:185)
at java.util.concurrent.locks.ReentrantLock.lock(ReentrantLock.java:261)
at java.util.concurrent.CopyOnWriteArrayList.removeRange(CopyOnWriteArrayList.java:569)
at java.util.concurrent.CopyOnWriteArrayList.remove(CopyOnWriteArrayList.java:366)
at java.util.concurrent.CopyOnWriteArrayList.remove(CopyOnWriteArrayList.java:376)
at android.view.ViewTreeObserver.removeOnPreDrawListener(ViewTreeObserver.java:377)

at android.widget.TextView.onDraw(TextView.java:4085)
at android.view.View.draw(View.java:6986)
at android.view.ViewGroup.drawChild(ViewGroup.java:1739)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466)
at android.view.ViewGroup.drawChild(ViewGroup.java:1737)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466)
at android.view.ViewGroup.drawChild(ViewGroup.java:1737)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466)
at android.view.View.draw(View.java:6989)
at android.view.ViewGroup.drawChild(ViewGroup.java:1739)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466)
at android.view.View.draw(View.java:6989)
at android.view.ViewGroup.drawChild(ViewGroup.java:1739)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466)
at android.view.ViewGroup.drawChild(ViewGroup.java:1737)

    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466)
at android.view.ViewGroup.drawChild(ViewGroup.java:1737)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466)
at android.view.View.draw(View.java:6989)
at android.view.ViewGroup.drawChild(ViewGroup.java:1739)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466)
at android.view.View.draw(View.java:6989)
at android.view.ViewGroup.drawChild(ViewGroup.java:1739)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466)
at android.view.ViewGroup.drawChild(ViewGroup.java:1737)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466)
at android.view.ViewGroup.drawChild(ViewGroup.java:1737)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466)
at android.view.View.draw(View.java:6989)
at android.widget.FrameLayout.draw(FrameLayout.java:361)
at android.view.ViewGroup.drawChild(ViewGroup.java:1739)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466)
at android.view.ViewGroup.drawChild(ViewGroup.java:1737)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466)

    at android.view.View.draw(View.java:6989)
at android.view.ViewGroup.drawChild(ViewGroup.java:1739)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466)
at android.view.View.draw(View.java:6989)
at android.view.ViewGroup.drawChild(ViewGroup.java:1739)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466)
at android.view.View.draw(View.java:7093)
at android.widget.FrameLayout.draw(FrameLayout.java:361)
at android.widget.ScrollView.draw(ScrollView.java:1421)
at android.view.ViewGroup.drawChild(ViewGroup.java:1739)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466)
at android.view.ViewGroup.drawChild(ViewGroup.java:1737)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466)
at android.view.View.draw(View.java:6989)
at android.widget.FrameLayout.draw(FrameLayout.java:361)
at android.view.ViewGroup.drawChild(ViewGroup.java:1739)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466)
at android.view.ViewGroup.d

As i checked my code i found no trace for stackoverflow . When i run same code on android 3.0 or above version it runs effectively and correct but not on android 2.3.3 & below 3.0 version . Please let me know if any one know about this issue ??

[EDIT] I am using Tab activity so main layout is Main.xml and in that sub activity holds view called firstTab_Results.xml , it holds a table layout which indeed performs the inflating max 20 views of inflate_table_firstTab.xml layout .

[EDIT 2] I am not recursing it anyway , it inflate Max 20 views(inflate_table_firstTab.xml) to table layout (firstTab_Results.xml) .

Note : Stackoverflow happens on single or dual core processor devices & without fullscreen mode .

解决方案

Your view hierarchy is too deep. When the hierarchy is drawn recursively, you run out of stack space and cannot go any deeper in the hierarchy, as observed in the stack trace.

Why this only occurs in earlier devices is because UI thread stack size is only 12kB in Android 2.3 devices but 16kB in later OS versions (ref).

How to reduce view hierarchy depth? Simply avoid nesting layouts whenever possible. The layouts you posted are too complex, no point fixing them for you within this Stack Overflow model (it takes some time to do correctly and it is likely too specific to help others), but here are some general guidelines:

  • Remove unnecessary layouts. For example, in your firsttab_results.xml you only need the TableLayout, the RelativeLayout and LinearLayout on top are pretty much useless. In your ScrollView there are at least 6 nested layouts when one or at most two would likely be enough.

  • A single child in a layout is a code smell. Most of the time the same can be achieved moving the child to its parent layout and adjusting the layout with margins.

  • There's usually little need to put layouts inside a RelativeLayout. Relative layout is powerful at laying out its children using relative positioning and child baseline alignment.

  • If you need a nested layout just for a background, try moving the background to e.g. just a View that is of the same size as the nested layout would be and laying out the other elements on top of it.

  • Pay attention to Android Lint warnings. The tool has become quite good at detecting view hierarchy complexities that could be simplified.

这篇关于计算器在Android 2.3.3设备只的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆