0

I've tried everything to try to get this to work. I am trying to get a tabbed window; I followed a tutorial and made sure every step was correct but every time I load it on to the AVD, it force closes. I am an amateur, so go easy on me! Any and all help will be appreciated.

Logcat:

06-24 20:49:29.564    1146-1146/com.michail.vector E/Trace﹕ error opening trace file: No such file or directory (2)
06-24 20:49:31.997    1146-1146/com.michail.vector E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.michail.vector/com.michail.vector.MainActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.michail.vector/com.michail.vector.SimpleVector}: java.lang.RuntimeException: Your content must have a TabHost whose id attribute is 'android.R.id.tabhost'
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
            at android.app.ActivityThread.access$600(ActivityThread.java:130)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4745)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.michail.vector/com.michail.vector.SimpleVector}: java.lang.RuntimeException: Your content must have a TabHost whose id attribute is 'android.R.id.tabhost'
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
            at android.app.ActivityThread.startActivityNow(ActivityThread.java:1900)
            at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:135)
            at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:347)
            at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:694)
            at android.widget.TabHost.setCurrentTab(TabHost.java:358)
            at android.widget.TabHost.addTab(TabHost.java:236)
            at com.michail.vector.MainActivity.onCreate(MainActivity.java:40)
            at android.app.Activity.performCreate(Activity.java:5008)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
            at android.app.ActivityThread.access$600(ActivityThread.java:130)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4745)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.RuntimeException: Your content must have a TabHost whose id attribute is 'android.R.id.tabhost'
            at android.app.TabActivity.onContentChanged(TabActivity.java:131)
            at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:259)
            at android.app.Activity.setContentView(Activity.java:1867)
            at com.michail.vector.SimpleVector.onCreate(SimpleVector.java:10)
            at android.app.Activity.performCreate(Activity.java:5008)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
            at android.app.ActivityThread.startActivityNow(ActivityThread.java:1900)
            at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:135)
            at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:347)
            at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:694)
            at android.widget.TabHost.setCurrentTab(TabHost.java:358)
            at android.widget.TabHost.addTab(TabHost.java:236)
            at com.michail.vector.MainActivity.onCreate(MainActivity.java:40)
            at android.app.Activity.performCreate(Activity.java:5008)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
            at android.app.ActivityThread.access$600(ActivityThread.java:130)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4745)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
            at dalvik.system.NativeStart.main(Native Method)
06-24 20:49:40.744      148-196/system_process E/PowerManagerService﹕ Excessive delay setting brightness: 193ms, mask=2
06-24 20:49:40.883      148-196/system_process E/PowerManagerService﹕ Excessive delay setting brightness: 141ms, mask=2
06-24 20:55:06.194      148-254/system_process E/ThrottleService﹕ problem during onPollAlarm: java.lang.IllegalStateException: problem parsing stats: java.io.FileNotFoundException: /proc/net/xt_qtaguid/iface_stat_all: open failed: ENOENT (No such file or directory)

MainActivity.java:

package com.michail.vector;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;

public class MainActivity extends TabActivity {

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //Create a new tabHost
        TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost);


        /** SINGLE VECTOR TAB **/
        //Used to keep track of tab
        TabSpec single = tabHost.newTabSpec("Single Vector");

        //Change tab indicator name and icon if necessary
        single.setIndicator("Single Vector");


        //Intent: Description of an operation to be performed
        Intent singleIntent = new Intent(this, SimpleVector.class);

        //Uses intent to launch activity as the tab content
        single.setContent(singleIntent);

        /** TWO VECTOR TAB**/
        TabSpec two = tabHost.newTabSpec("Two Vectors");
        two.setIndicator("Two Vectors");
        Intent TwoIntent = new Intent(this, TwoVectors.class);
        two.setContent(TwoIntent);

        //Add the tabs
        tabHost.addTab(single);
        tabHost.addTab(two);

    }

}

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>

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


        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical">

            <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">

                <LinearLayout
                    android:id="@+id/tab1"
                    android:orientation="vertical"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"/>

                <LinearLayout
                    android:id="@+id/tab2"
                    android:orientation="vertical"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"/>

            </FrameLayout>
        </LinearLayout>
    </TabHost>

AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.michail.vector"
    android:versionCode="1"
    android:versionName="1.0">

    <application
        android:icon="@drawable/ic_launcher"
        android:label="Vectors"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="Vectors" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity android:name=".SimpleVector" />
        <activity android:name=".TwoVectors" />

    </application>

</manifest>

If I need to provide any other classes associated or xml files, please just ask. I included what I thought was necessary to answer the question. Thanks in advance.

EDIT: Instead of tabs, I've decided to use a main screen with buttons. It's a simple design and I know that it'll work

Joe Michail
  • 429
  • 5
  • 14

2 Answers2

1

Extending TabActivity should be done like below:

TabHost mTabHost = getTabHost();

Note that tabhost is depreciated and it is recommended to use TabLayout with fragments.

Illegal Argument
  • 10,090
  • 2
  • 44
  • 61
0

Hey i just had the same problem like you but i had to extend my MainActivity from TabActivity to Activity and clean my project. every thing runned just fine. try it

Mwesigye John Bosco
  • 1,148
  • 2
  • 11
  • 14