我们的新版本在神机(三星G9100,Android4.0.4)上出现了一个必现的crash,拉取某一个订阅源的时候会出现闪退。
logcat拿到的日志显示:
E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.StackOverflowError
at java.lang.reflect.Array.newInstance(Array.java:448)
at android.text.SpannableStringInternal.getSpans(SpannableStringInternal.java:272)
at android.text.SpannedString.getSpans(SpannedString.java:25)
at android.text.Layout$SpannedEllipsizer.getSpans(Layout.java:1790)
at android.text.TextLine$SpanSet.init(TextLine.java:878)
at android.text.TextLine.handleRun(TextLine.java:976)
at android.text.TextLine.drawRun(TextLine.java:397)
at android.text.TextLine.draw(TextLine.java:195)
at android.text.Layout.draw(Layout.java:425)
at android.widget.TextView.onDraw(TextView.java:5262)
at android.view.View.draw(View.java:11159)
at android.view.View.getDisplayList(View.java:10598)
at android.view.ViewGroup.drawChild(ViewGroup.java:2858)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2497)
at android.view.View.getDisplayList(View.java:10596)
at android.view.ViewGroup.drawChild(ViewGroup.java:2858)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2497)
at android.view.View.getDisplayList(View.java:10596)
at android.view.ViewGroup.drawChild(ViewGroup.java:2858)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2497)
at android.view.View.getDisplayList(View.java:10596)
at android.view.ViewGroup.drawChild(ViewGroup.java:2858)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2497)
at android.view.View.draw(View.java:11162)
at android.view.View.getDisplayList(View.java:10598)
at android.view.ViewGroup.drawChild(ViewGroup.java:2858)
at android.widget.ListView.drawChild(ListView.java:3231)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2497)
at android.widget.AbsListView.dispatchDraw(AbsListView.java:2281)
at android.widget.ListView.dispatchDraw(ListView.java:3226)
at com.netease.pris.activity.view.pullrefresh.PullToRefreshListView$InternalListView.dispatchDraw(PullToRefreshListView.java:312)
at android.view.View.draw(View.java:11162)
at android.widget.AbsListView.draw(AbsListView.java:3764)
at android.view.View.getDisplayList(View.java:10598)
at android.view.ViewGroup.drawChild(ViewGroup.java:2858)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2497)
at android.view.View.getDisplayList(View.java:10596)
at android.view.ViewGroup.drawChild(ViewGroup.java:2858)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2497)
at android.view.View.draw(View.java:11162)
at android.view.View.getDisplayList(View.java:10598)
at android.view.ViewGroup.drawChild(ViewGroup.java:2858)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2497)
at android.view.View.getDisplayList(View.java:10596)
at android.view.ViewGroup.drawChild(ViewGroup.java:2858)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2497)
at android.view.View.draw(View.java:11162)
at android.view.View.getDisplayList(View.java:10598)
at android.view.ViewGroup.drawChild(ViewGroup.java:2858)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2497)
at android.view.View.getDisplayList(View.java:10596)
at android.view.ViewGroup.drawChild(ViewGroup.java:2858)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2497)
at android.view.View.draw(View.java:11162)
at android.support.v4.view.ViewPager.draw(ViewPager.java:2262)
at android.view.View.getDisplayList(View.java:10598)
at android.view.ViewGroup.drawChild(ViewGroup.java:2858)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2497)
at android.view.View.getDisplayList(View.java:10596)
at android.view.ViewGroup.drawChild(ViewGroup.java:2858)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2497)
at android.view.View.getDisplayList(View.java:10596)
at android.view.ViewGroup.drawChild(ViewGroup.java:2858)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2497)
at android.view.View.getDisplayList(View.java:10596)
at android.view.ViewGroup.drawChild(ViewGroup.java:2858)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2497)
at android.view.View.draw(View.java:11162)
at android.support.v4.view.ViewPager.draw(ViewPager.java:2262)
at android.
从前几行来看,应该是文本控件text的问题。textView:本身就有2层,如果在textView中用了SpannableStringBuilder,就会变成4层。层级太深导致的堆栈溢出,进而产生crash。
原先用Spannable实现的效果改为setCompoundDrawablesWithIntrinsicBounds实现,也就是:title.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);