0

Ive been trying to fix this for ages, on the tab tutorial for android ive followed it exactly but keep getting this error messege on my TabWidget.java class.

R.drawable.ic_tab_albums cannot be resolved
tabWidget.java/HelloTabWidget/src/com/example/tabwidget

and

R.drawable.ic_tab_songs cannot be resolved
tabWidget.java/HelloTabWidget/src/com/example/tabwidget

Heres my code for my TabWidget.java class

`
import com.example.androidtab.R;

 import android.app.Activity;
 import android.content.Intent;
 import android.content.res.Resources;
 import android.os.Bundle;
 import android.widget.TabHost;

public class TabWidget extends Activity {
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Resources res = getResources(); // Resource object to get Drawables
    TabHost tabHost = getTabHost();  // The activity TabHost
    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(this, ArtistsActivity.class);

    // Initialize a TabSpec for each tab and add it to the TabHost
    spec = tabHost.newTabSpec("artists").setIndicator("Artists",
                      res.getDrawable(R.drawable.ic_tab_artists))
                  .setContent(intent);
    tabHost.addTab(spec);

    // Do the same for the other tabs
    intent = new Intent().setClass(this, AlbumsActivity.class);
    spec = tabHost.newTabSpec("albums").setIndicator("Albums",
                      res.getDrawable(R.drawable.ic_tab_albums))
                  .setContent(intent);
    tabHost.addTab(spec);

    intent = new Intent().setClass(this, SongsActivity.class);
    spec = tabHost.newTabSpec("songs").setIndicator("Songs",
                      res.getDrawable(R.drawable.ic_tab_songs))
                  .setContent(intent);
    tabHost.addTab(spec);

    tabHost.setCurrentTab(2);
}

private TabHost getTabHost() {
    // TODO Auto-generated method stub
    return null;
}

}`

  • 1
    See my question : http://stackoverflow.com/questions/2209406/issues-with-android-tabhost-example – KevinDTimm Dec 14 '10 at 19:31
  • refer particularly to the answer by Ted that KevinDTimm is linking to. it points out that the tutorial has not instructed you to create the other 2 xml files needed to make this example work. – Pure Function Dec 15 '10 at 03:04

2 Answers2

2

That is covered in step #3 of the tutorial.

"You need an icon for each of your tabs. For each icon, you should create two versions: one for when the tab is selected and one for when it is unselected."

You only created an icon for one, not for all three.

Admittedly, this step is pretty poorly written.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
1

Also you need to make a separate class file for each activity class (ie ArtistsActivity.java, AlbumsActivity.java and SongsActivity.java) in your src folder.

I was not doing so and the project was not even start when I ran it.

Hopefully the revision will be made to the tutorial so no extra time losses happened.