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 4267478
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T06:54:18+00:00 2026-05-21T06:54:18+00:00

I am working on the Andriod Tab Layout App to get use to the

  • 0

I am working on the Andriod Tab Layout App to get use to the andriod programing. I know there are alot of questions about this tutorial but i havent seem to be able to find what is wrong. Below is is the code i have. Also how do i get the error logs? — i notice thats what all the posts ask for. I am running it on an andriod phone and my IDE is eclipse. It compiles fine but when i run it I get a black screen with a force close box. Thanks in advance!

My main java file:

    package greg.tab;

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

public class tab extends TabActivity {
     /** Called when the activity is first created. */

    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); 

        //Create an indent
        intent = new Intent().setClass(this, SongActivity.class);
        //Initialize

        spec = tabHost.newTabSpec("albums").setIndicator("Albums", res.getDrawable(R.drawable.ic_tab_artists))
        .setContent(intent);
        tabHost.addTab(spec);


        //Create an indent
        intent = new Intent().setClass(this, AlbumActivity.class);
        //Initialize

        spec = tabHost.newTabSpec("songs").setIndicator("Songs", res.getDrawable(R.drawable.ic_tab_artists))
        .setContent(intent);
        tabHost.addTab(spec);
        tabHost.setCurrentTab(2);     
    }

    public class ArtistsActivity extends Activity {
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            TextView textview = new TextView(this);
            textview.setText("This is The Artists tab");
            setContentView(textview);
        }
    }

    public class AlbumActivity extends Activity {
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            TextView textview = new TextView(this);
            textview.setText("This is The Album tab");
            setContentView(textview);
        }
    }
    public class SongActivity extends Activity {
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            TextView textview = new TextView(this);
            textview.setText("This is The song tab");
            setContentView(textview);
        }
    }
}

–My XML manifest

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="greg.tab"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".tab"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

<activity android:name=".ArtistsActivity"
android:label ="@string/app_name">
</activity>
<activity android:name=".AlbumActivity"
android:label ="@string/app_name"></activity>
<activity android:name=".SongActivity"
android:label ="@string/app_name">
</activity>
    </application>


</manifest>

–my xml file made for my image selector (i just used a regular XML file–i hope this is right) –also i use this for all tabs

    <?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">   
 <!-- When selected, use grey -->   
  <item android:drawable="@drawable/ic_tab_artists_grey" 
           android:state_selected="true" />   
            <!-- When not selected, use white-->   
             <item android:drawable="@drawable/ic_tab_artists_white" />
             </selector>

–My Main XML file

<?xml version="1.0" encoding="utf-8"?>
<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
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:padding="5dp">
        <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>

Again any help is appreciated!

Thanks.

  • 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-21T06:54:19+00:00Added an answer on May 21, 2026 at 6:54 am

    Try this link how to use logcat

    For the force close :check you resources(layout+drawables),id you are giving in xml and id you are using in your code.
    clean you project and run it
    hope this help!

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

Sidebar

Related Questions

I am trying to get swipe gestures working with a tab layout in an
I trying to get the tabview app to work, its working fine in the
So I have my tab layout working as demonstrated in the Android example :
I'm working on an Android app having an always visible tabbar. However, each tab
I have an app on android market which was working fine on tab before.
i am working in android. I want to make TabHost and Tab widget. this
I'm trying to get a tabbed layout working on android. Using an example I
I am now working with Android TabWidget. I build this TabWidget based on http://mobileorchard.com/android-app-development-tabbed-activities/
I'm working on an Android application with an activity that uses a tab layout.
I am working with two fragments in Android Honeycomb (Tab). In the left is

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.