Honeycomb and TabHost specs

佐手、 提交于 2019-11-29 14:32:24

I believe I've found a solution, but because people are curious, here is the stacktrace I got when I ran into this problem:

05-17 13:09:53.462: ERROR/CustomExceptionHandler(500): Uncaught throwable in thread Thread[main,5,main]
    android.content.res.Resources$NotFoundException: Resource ID #0x0
    at android.content.res.Resources.getValue(Resources.java:1014)
    at android.content.res.Resources.loadXmlResourceParser(Resources.java:2039)
    at android.content.res.Resources.getLayout(Resources.java:853)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:389)
    at android.widget.TabHost$LabelAndIconIndicatorStrategy.createIndicatorView(TabHost.java:568)
    at android.widget.TabHost.addTab(TabHost.java:226)
    at com.myApp.ui.TabDialog.addTab(TabDialog.java:80)
    ...

At that line, I have code roughly equivalent to what sparky saw:

spec = myTabHost.newTabSpec("score_game").setIndicator("Score", res.getDrawable(R.drawable.icon_field_gloss)).setContent(intent);
myTabHost.addTab(spec);

Note that myTabHost is a TabHost and spec is a TabSpec.

Previously, I was initializing myTabHost like this:

//WRONG - This can CRASH your app starting at Android SDK 3.0
TabHost myTabHost = new TabHost(getContext()); 

To fix this problem, I started initializing the TabHost by doing this:

TabHost myTabHost = new TabHost(getContext(), null); 

And that fixed it! I would love to find a root cause, but I haven't yet been able to figure it out.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!