gbhall
gbhall

Reputation: 13279

Android - getTabHost() is undefined

I started learning Java and how to program for Android last night :)

So far I'm on this tutorial: developer.android.com/resources/tutorials/views/hello-tabwidget.html

Clearly these tutorials have been designed for people that already have experience with Java.

Despite the tutorial lacking all the required steps (for an absolute beginner with Java) and even having a typo, it seems I've figured everything out (which I'm really proud of :p). Except I cannot figure out how to fix TabHost tabHost = getTabHost(); which apparently is undefined.

I have one other error shown in the linked image below, but I don't see why.

Here is the linked image.

Thanks, Gareth

Upvotes: 3

Views: 29097

Answers (3)

Boris Georgiev
Boris Georgiev

Reputation: 61

Now that TabActivity is deprecated in API level 13, it is recommended to use Fragments instead. Still possible, however, to use a support library for compatibility back to DONUT.

Upvotes: 0

David
David

Reputation: 2637

You just missed step 5 of the tutorial.

The other error is due to the capital T on TabHost. You want: tabHost.addTab(spec);

Java is case sensitive, so it makes a difference (calling a non-exsistant static method of the TabHost class vs. calling an instance method on the object referenced by the tabHost variable).

Upvotes: 6

AaronM
AaronM

Reputation: 1577

getTabHost() is a method of TabActivity not Activity. You'll need to extend that instead of Activity for the method to be defined in your object.

Upvotes: 24

Related Questions