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

  • SEARCH
  • Home
  • 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 8638301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:41:41+00:00 2026-06-12T10:41:41+00:00

I want to switch from one Tab to another tab. For that i am

  • 0

I want to switch from one Tab to another tab. For that i am using below code:

public void switchTabInActivity(int indexTabToSwitchTo){
    AccidentTabActivity ParentActivity;
    ParentActivity = (AccidentTabActivity) getParent(); // here i am getting exception
    ParentActivity.switchTab(indexTabToSwitchTo);
    }

I am calling this method from which i want to navigate.

But i got exception of cast class.

Log cat:

10-04 15:39:22.327: ERROR/AndroidRuntime(1016): FATAL EXCEPTION: main
10-04 15:39:22.327: ERROR/AndroidRuntime(1016): java.lang.ClassCastException: com.project.AccidentApp.TabGroupHomeActivity
10-04 15:39:22.327: ERROR/AndroidRuntime(1016):     at com.project.AccidentApp.KnowWhatToDoMenuActivity.switchTabInActivity(KnowWhatToDoMenuActivity.java:189)
10-04 15:39:22.327: ERROR/AndroidRuntime(1016):     at com.project.AccidentApp.KnowWhatToDoMenuActivity$3.onClick(KnowWhatToDoMenuActivity.java:155)
10-04 15:39:22.327: ERROR/AndroidRuntime(1016):     at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:159)
10-04 15:39:22.327: ERROR/AndroidRuntime(1016):     at android.os.Handler.dispatchMessage(Handler.java:99)
10-04 15:39:22.327: ERROR/AndroidRuntime(1016):     at android.os.Looper.loop(Looper.java:130)
10-04 15:39:22.327: ERROR/AndroidRuntime(1016):     at android.app.ActivityThread.main(ActivityThread.java:3683)
10-04 15:39:22.327: ERROR/AndroidRuntime(1016):     at java.lang.reflect.Method.invokeNative(Native Method)
10-04 15:39:22.327: ERROR/AndroidRuntime(1016):     at java.lang.reflect.Method.invoke(Method.java:507)
10-04 15:39:22.327: ERROR/AndroidRuntime(1016):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
10-04 15:39:22.327: ERROR/AndroidRuntime(1016):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
10-04 15:39:22.327: ERROR/AndroidRuntime(1016):     at dalvik.system.NativeStart.main(Native Method)

UPDATED

TabGroupHomeActivity.java

public class TabGroupHomeActivity extends TabGroupActivity{ 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        startChildActivity("KnowWhatToDoMenuActivity", new Intent(this,KnowWhatToDoMenuActivity.class));
    }


}

AccidentTabActivity.java

public class AccidentTabActivity extends TabActivity 
{
    private TabHost tabHost;
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_tab);

        tabHost = getTabHost();  // The activity TabHost
        TabHost.TabSpec spec;  // Resusable TabSpec for each tab
        Intent intent;  // Reusable Intent for each tab

        /////////////////////////////
        intent = new Intent().setClass(this,TabGroupHomeActivity.class);
        // Initialize a TabSpec for each tab and add it to the TabHost
        spec = tabHost.newTabSpec("Menu").setIndicator(prepareTabView("Menu",R.drawable.menul)).setContent(intent);
        tabHost.addTab(spec); // error at this line

        intent = new Intent().setClass(this,TabGroupStepsActivity.class);
        // Initialize a TabSpec for each tab and add it to the TabHost
        spec = tabHost.newTabSpec("Steps").setIndicator(prepareTabView("Steps",R.drawable.tab_step)).setContent(intent);
        tabHost.addTab(spec); 

        intent = new Intent().setClass(this,TabGroupProfileActivity.class);
        // Initialize a TabSpec for each tab and add it to the TabHost
        spec = tabHost.newTabSpec("Profile").setIndicator(prepareTabView("Profile",R.drawable.tab_profile)).setContent(intent);
        tabHost.addTab(spec);       

        intent = new Intent().setClass(this,TabGroupContactUsActivity.class);
        // Initialize a TabSpec for each tab and add it to the TabHost
        spec = tabHost.newTabSpec("Contact").setIndicator(prepareTabView("Menu",R.drawable.tab_contact)).setContent(intent);
        tabHost.addTab(spec);


        tabHost.setCurrentTab(0);




    }

     private View prepareTabView(String text, int resId) {
         View view = LayoutInflater.from(this).inflate(R.layout.tabs, null);
         ImageView iv = (ImageView) view.findViewById(R.id.tabImageView);
         TextView tv = (TextView) view.findViewById(R.id.tabTextView);
         iv.setImageResource(resId);
         tv.setText(text);
         return view;
    }

     public void switchTab(int tab){

         //getLocalActivityManager().getActivity(tab);
            //String strTab = ""+tab;
            tabHost.setCurrentTab(tab);


    }
}
  • 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-06-12T10:41:42+00:00Added an answer on June 12, 2026 at 10:41 am

    Try to declare tabhost as static and call in child activity as below..

    Instead private TabHost tabHost;

    try static TabHost tabHost;

    And in your Child Activity

     AccidentTabActivity.tabHost.setCurrentTab(2);
    

    Then you can set your current tab as you want.

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

Sidebar

Related Questions

i have a tabActivity that hold 3 tabs. from one tab i want to
I want to be able to switch from one file to another in the
I want to switch from one screen to another - from a category screen
I want programatically switch from one view controller to another. I use the following
I have a multiview application using a tab bar to switch views. One is
I am using PHP, for some reason and I want to switch sessions from
For using custom DNS, I want to switch from shared mode to reserved mode
I want to Switch from Web Designer to Front End Developer or web developer
I want to be able to switch from the current db to multiple dbs
I want to switch a file upload from FTP to SFTP. But I cannot

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.