4

初始化tabhost时我的android应用程序崩溃了。但是来自用户的崩溃日志很奇怪!

大部分崩溃来自 android 2.3.x,在 android 4.x 上运行良好。

我可以看到当我调用“setImageResource”时代码遇到了无限递归,但我不明白为什么。代码:

    查看 tabIndicator = LayoutInflater.from(this).inflate(R.layout.tab_indicator, getTabWidget(), false);   
    ImageView 图标 = (ImageView) tabIndicator.findViewById(R.id.icon);
    icon.setImageResource(drawableId); // 崩溃了
    java.lang.StackOverflowError
at android.graphics.drawable.StateListDrawable$StateListState.<init>(StateListDrawable.java:257)
at android.graphics.drawable.StateListDrawable.<init>(StateListDrawable.java:303)
at android.graphics.drawable.StateListDrawable.<init>(StateListDrawable.java:70)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:787)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:728)
at android.content.res.Resources.loadDrawable(Resources.java:1712)
at android.content.res.Resources.getDrawable(Resources.java:590)
at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:162)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:787)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:728)
at android.content.res.Resources.loadDrawable(Resources.java:1712)
at android.content.res.Resources.getDrawable(Resources.java:590)
at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:162)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:787)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:728)
at android.content.res.Resources.loadDrawable(Resources.java:1712)
at android.content.res.Resources.getDrawable(Resources.java:590)
at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:162)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:787)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:728)
at android.content.res.Resources.loadDrawable(Resources.java:1712)
at android.content.res.Resources.getDrawable(Resources.java:590)
at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:162)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:787)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:728)
at android.content.res.Resources.loadDrawable(Resources.java:1712)
at android.content.res.Resources.getDrawable(Resources.java:590)
at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:162)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:787)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:728)
at android.content.res.Resources.loadDrawable(Resources.java:1712)
at android.content.res.Resources.getDrawable(Resources.java:590)
at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:162)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:787)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:728)
at android.content.res.Resources.loadDrawable(Resources.java:1712)
at android.content.res.Resources.getDrawable(Resources.java:590)
at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:162)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:787)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:728)
at android.content.res.Resources.loadDrawable(Resources.java:1712)
at android.content.res.Resources.getDrawable(Resources.java:590)
at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:162)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:787)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:728)
at android.content.res.Resources.loadDrawable(Resources.java:1712)
at android.content.res.Resources.getDrawable(Resources.java:590)
at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:162)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:787)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:728)
at android.content.res.Resources.loadDrawable(Resources.java:1712)
at android.content.res.Resources.getDrawable(Resources.java:590)
at android.widget.ImageView.resolveUri(ImageView.java:564)
at android.widget.ImageView.setImageResource(ImageView.java:280)
at com.thankcreate.care.MainActivity.addTab(MainActivity.java:95)
at com.thankcreate.care.MainActivity.setTabs(MainActivity.java:78)
at com.thankcreate.care.MainActivity.onCreate(MainActivity.java:36)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1072)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1794)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1851)
at android.app.ActivityThread.access$1500(ActivityThread.java:132)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1038)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:143)
at android.app.ActivityThread.main(ActivityThread.java:4277)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
4

1 回答 1

3

这是由执行无限循环引起的。这可能是由用作图标的可绘制对象中的循环调用引起的。具有指定的 DrawabledrawableId可能正在调用第二个可绘制对象,而第二个可绘制对象又会调用第一个。

提供有关您正在使用的可绘制对象的更多详细信息。这可能有助于提供更好的答案。

于 2013-01-10T07:14:01.553 回答