Java – Bug Run Android tutorial HelloTabWidget under SDK 1.5: “setCurrentTag(getIntent())”

Bug Run Android tutorial HelloTabWidget under SDK 1.5: “setCurrentTag(getIntent())”… here is a solution to the problem.

Bug Run Android tutorial HelloTabWidget under SDK 1.5: “setCurrentTag(getIntent())”

Do not compile. In fact: even in 1.5, this api getIntent() has been listed as deprecated.

The error message I get says getIntent() doesn’t return a string, but setCurrentTab() requires one.

If I guess and change the line to:

“tabHost.setCurrentTab(1);//is setCurrentTab(getIntent()”,

Then it compiles, builds, but doesn’t run. I get an “unexpected stop” error message from the emulator. I can’t even get Log.d to output, so it seems to have stopped “unexpectedly” quite early.

So the first and main problem is: What is the correct fix for “tabHost.setCurrentTab(getIntent()” in the last line of OnCreate() in ?

The second and simpler question is: replace “mTabHost” with tabHost where this happens, am I guessing right?


Here are the issues and fixes for that particular tutorial:

Step 2: When creating activities, you need to manually add them to the list if you didn’t create them from list.

Add these lines to the AndroidManifest.xml:

  <activity android:name=". AlbumsActivity"
  <activity android:name=". ArtistsActivity"
          <activity android:name=". SongsActivity"

Step 3: You are only instructed to create ic_tab_artists.xml files. You also need to create one for ic_tab_songs.xml and ic_tab_albums.xml. You can copy just the ic_tab_artists.xml (or change the tab specification to use the artists.xml file for each tab).

Step 4: The penultimate line under /res/layout/main has a typo (a; Instead of 🙂

      android:padding="5dp" />

Step 6: There is a typo using the call mTabHost instead of tabHost. Change it.

As mentioned earlier, the getIntent() function on the last line is inappropriate. I just call the tab based on its ID. For example:


Related Problems and Solutions