Honeycomb and TabHost Specifications

I have a question about Honeycomb backward compatibility. I have an application that supports 2.1 or higher, and it seems to work mostly on Honeycomb, unless they launch TabActivity.

In particular, when I add tabs to TabHost, I get the following exception

android.content.res.Resources $ NotFoundException: Resource ID # 0x0

When looking at the code that throws this exception, I see that this is a tab specification that has a label and icon in it. Inside the code in LabelAndIconIndicatorStrategy is trying to inflate the R.layout.tab_indicator layout file, which seems to be unavailable.

TabHost.TabSpec spec; // Resusable TabSpec for each tab Intent intent; // Reusable Intent for each tab // Create an Intent to launch an Activity for the tab (to be reused) intent = new Intent().setClass(_gameActivity, ScoreGameActivity.class); intent.putExtra(GameChangerConstants.STREAM_ID, _stream.pk().toString()); // Initialize a TabSpec for each tab and add it to the TabHost spec = _gameTabHost.newTabSpec("score_game").setIndicator("Score", res.getDrawable(R.drawable.icon_field_gloss)).setContent(intent); _gameTabHost.addTab(spec); 

Is there a new way to create tabs for honeycombs that I don’t know about? I poured the documentation, but did not see anything that indicates a problem with what I did.

I would like to avoid using fragments at this stage until we can do a more complete restructuring of our user interface widgets, and I would like to better understand this problem.

+4
source share
1 answer

I believe that I found a solution, but because people are curious, here is the stack I received 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) ... 

On this line, I have code roughly equivalent to what I saw:

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

Note that myTabHost is TabHost and spec is TabSpec.

I used to initialize myTabHost as follows:

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

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

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

And that fixed it! I would love to find the root cause, but I still could not understand it.

+14
source

Source: https://habr.com/ru/post/1344958/


All Articles