TabHost stürzt ab

C

Chris92

Fortgeschrittenes Mitglied
0
Hallo ich wollte fragen ob jemand vieleicht weis wo mein Fehler liegt dass beim starten einens Test Programmes mit einem TabHost die Applikation immer abstürzt. Im Code wird mir kein Fehler angezeigt. Ich benutzte die Android 2.0.1 Emulator Version. Hier mein Code:
Tab.java Datei:
Code:
package com.example.tab;

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

public class Tab extends TabActivity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        /** TabHost will have Tabs */
        TabHost tabHost = (TabHost)findViewById(android.R.id.tabhost);

        /** TabSpec used to create a new tab.
         * By using TabSpec only we can able to setContent to the tab.
         * By using TabSpec setIndicator() we can set name to tab. */

        /** tid1 is firstTabSpec Id. Its used to access outside. */
        TabSpec firstTabSpec = tabHost.newTabSpec("tid1");
        TabSpec secondTabSpec = tabHost.newTabSpec("tid1");

        /** TabSpec setIndicator() is used to set name for the tab. */
        /** TabSpec setContent() is used to set content for a particular tab. */
        firstTabSpec.setIndicator("First Tab Name").setContent(new Intent(this,FirstTab.class));
        secondTabSpec.setIndicator("Second Tab Name").setContent(new Intent(this,SecondTab.class));

        /** Add tabSpec to the TabHost to display. */
        tabHost.addTab(firstTabSpec);
        tabHost.addTab(secondTabSpec);

    }
}
main.xml Datei
Code:
<?xml version="1.0" encoding="utf-8"?>
<TabHost android:layout_width="fill_parent"
    android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost">
    <LinearLayout android:id="@+id/LinearLayout01"
        android:orientation="vertical" android:layout_height="fill_parent"
        android:layout_width="fill_parent">
        <TabWidget android:id="@android:id/tabs"
            android:layout_height="wrap_content" android:layout_width="fill_parent"></TabWidget>
        <FrameLayout android:id="@android:id/tabcontent"
            android:layout_height="fill_parent" android:layout_width="fill_parent"></FrameLayout>
    </LinearLayout>
</TabHost>
Androidmanifest Datei
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.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=".FirstTab" android:label="First Tab"></activity>
    <activity android:name=".SecondTab" android:label="First Tab"></activity>
    </application>
</manifest>
FirstTab.java
Code:
package com.example.tab;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class FirstTab extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        /* First Tab Content */
        TextView textView = new TextView(this);
        textView.setText("First Tab");
        setContentView(textView);

    }
}
SecondTab.java
Code:
package com.example.tab;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class SecondTab extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        /* Second Tab Content */
        TextView textView = new TextView(this);
        textView.setText("Second Tab");
        setContentView(textView);

    }
}
Ich hoffe ihr könnt mir weiter helfen.

MFG Chris92
 
wie in den meisten threads:

logcat mit rein kopieren, macht die suche wesentlich einfacher
 
Wie stelle ich das an? Hab vorher noch nicht damit gearbeitet

MFG Chris92
 
eclipse view logcat
 

Ähnliche Themen

S
Antworten
8
Aufrufe
512
swa00
swa00
P
Antworten
6
Aufrufe
1.082
Phillip1996
P
Zurück
Oben Unten