Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6756007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:28:17+00:00 2026-05-26T13:28:17+00:00

I have problem with initializing TabHost. I need to have in View several Tabs

  • 0

I have problem with initializing TabHost. I need to have in View several Tabs which show different activities: one must show google map, second – log in form. In created code there is error “The method getTabHost() is undefined for the type MapViewDemo”

package com.example.android.apis.view;

import java.util.List;
import android.app.*;
import com.example.android.google.apis.R;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;
import android.widget.TabHost;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.widget.*;
import com.example.android.apis.view.GMapManager;

public class MapViewDemo extends MapActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mapview);
        MapView mMapView = (MapView) findViewById(R.id.mapview);

        mMapView.setBuiltInZoomControls(true);
        MapController mMapController = mMapView.getController();
        double x, y;
        x = 59.434034;
        y = 24.757687;
        double[] xy = {x,y};
        GeoPoint p = coordinatesToGeoPoint(xy);
        mMapController.animateTo(p);
        mMapController.setZoom(18);
        mMapView.invalidate();
        mMapView.setBuiltInZoomControls(true);

        List<Overlay> mapOverlays = mMapView.getOverlays();
        Drawable drawable = this.getResources().getDrawable(R.drawable.marker_green);
        HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(drawable);

        GeoPoint point = p;
        OverlayItem overlayitem = new OverlayItem(point, "123!", "");

        itemizedoverlay.addOverlay(overlayitem);
        mapOverlays.add(itemizedoverlay);

        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

        // Do the same for the other tabs
                intent = new Intent().setClass(this, GMapManager.class);
                spec = tabHost
                        .newTabSpec("manager")
                        .setIndicator("Manager",
                                res.getDrawable(R.drawable.ic_tabs))
                        .setContent(intent);
                tabHost.addTab(spec);

                intent = new Intent().setClass(this, MapViewDemo.class);
                spec = tabHost
                        .newTabSpec("map")
                        .setIndicator("Map", res.getDrawable(R.layout.mapview))
                        .setContent(intent);
                tabHost.addTab(spec);

                tabHost.setCurrentTab(2);



    }

    @Override
    protected boolean isRouteDisplayed() { return false; }
    /**
     * Converts a pair of coordinates to a GeoPoint
     * 
     * @param coords double containing latitude and longitude
     * @return GeoPoint for the same coords
     */
    public static GeoPoint coordinatesToGeoPoint(double[] coords) {
        if (coords.length > 2) {
            return null;
        }
        if (coords[0] == Double.NaN || coords[1] == Double.NaN) {
            return null;
        }
        final int latitude = (int) (coords[0] * 1E6);
        final int longitude = (int) (coords[1] * 1E6);
        return new GeoPoint(latitude, longitude);
    }

}

Eclipse offered me to create method getTabHost(). I accepted. Eclipse created it, but I don’t see it in my current class any changes. Now it can compile but produces RuntimeException. Here is stack trace:

Thread [<1> main] (Suspended (exception RuntimeException))  
    ActivityThread.performLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 1955    
    ActivityThread.handleLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 1980 
    ActivityThread.access$600(ActivityThread, ActivityThread$ActivityClientRecord, Intent) line: 122    
    ActivityThread$H.handleMessage(Message) line: 1146  
    ActivityThread$H(Handler).dispatchMessage(Message) line: 99 
    Looper.loop() line: 137 
    ActivityThread.main(String[]) line: 4340    
    Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]  
    Method.invoke(Object, Object...) line: 511  
    ZygoteInit$MethodAndArgsCaller.run() line: 784  
    ZygoteInit.main(String[]) line: 551 
    NativeStart.main(String[]) line: not available [native method]

And here is my layout.xml

<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/main"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:padding="5dp" >

        <com.google.android.maps.MapView
            android:id="@+id/mapview"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:apiKey="03xx7gYjYkcIs5nDM_44v02HgLCmO3Bcega19yA"
            android:clickable="true"
            android:enabled="true" />


        <TextView
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:padding="10dp"
            android:textSize="16sp" >
        </TextView>

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:padding="5dp" />
    </LinearLayout>

</TabHost>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T13:28:18+00:00Added an answer on May 26, 2026 at 1:28 pm

    getTabHost() is method only found in TabActivity

    and if you want to add get Tabs other than TabActivity, put TabHost in layout.xml and then try this way:

    TabHost tabHost = (TabHost)this.findViewById(R.id.tab_host_id);
    tabHost.setup(); // dont forget to call this line.
    

    For more detail go here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem initializing an array whose size is defined as extern const.
I have a problem with initializing my app properly after the autostart. I've managed
I have a view from which I have to select data between 2 given
I have a problem with initializing the application. JNDI lookup is not fully initialized
i am newbie at c++ and i have problem initializing my container occ_stat_t using
i am having a weird problem with uialert views. i have several alerts are
I'm having some problems initializing static string members in c++. I have several classes
I'm trying to solve a problem similar to the one described here Initializing strongly
I have problem in some JavaScript that I am writing where the Switch statement
I have problem with return statment >.< I want to store all magazine names

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.