I have recently started Android development, and i already know Java. So i was following
This tutorial on the android development site about how to create a tabbed layout.
Even though i went after everything in the tutorial and eclipse prompts no errors, the application crashes when i run it on a froyo API level 8 Emulator. My application is build as well on API level 8.
What i think might cause it:
1) I seem to have a warning in the AndroidManifest.xml which i dont understand, it highlights this line:
<uses-sdk android:minSdkVersion="8" />
2) In the tutorial they created a page with 3 tabs, while im using 5 tabs. maybe thats it??]
My code:
Main activity:
package ent.com;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.TabHost;
public class TestActivity extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Resources res = getResources();
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
Intent intent;
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, Players.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("players").setIndicator("Players",
res.getDrawable(R.drawable.ic_tab_players))
.setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs
intent = new Intent().setClass(this, Staff.class);
spec = tabHost.newTabSpec("staff").setIndicator("Staff",
res.getDrawable(R.drawable.ic_tab_staff))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, League.class);
spec = tabHost.newTabSpec("league").setIndicator("League",
res.getDrawable(R.drawable.ic_tab_league))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, Finance.class);
spec = tabHost.newTabSpec("finance").setIndicator("Finance",
res.getDrawable(R.drawable.ic_tab_finance))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, Next.class);
spec = tabHost.newTabSpec("next").setIndicator("Next Game",
res.getDrawable(R.drawable.ic_tab_next))
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(2);
}
}
My AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ent.com"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".TestActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Thanks for any help!
you need to mention every other activity in the manifest too.
an activity undeclared in the manifest can cause the app to crash.