Reputation: 302
I am creating an android app myself (min sdk version 7 or 2.1 and up). And it was going fine until I decided I was going to need a TabLayout. I added a new class, and had it extend TabActivity, however when launching the app in an AVD it crashed and stated this in the log that there was an uncaught exception. And that it could not launch the activity.
ThermostatTabHost.java (note, I did not add package/import to save some space):
public class ThermostatTabHost extends TabActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tabmain);
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, ThermostatActivity.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("Temperature").setIndicator("Program",
res.getDrawable(R.drawable.arrow_up))
.setContent(intent);
tabHost.addTab(spec);
}
}
The ThermostatActvity class currently only holds a onCreate function which calls super.onCreate(savedInstance) and sets a layout with a textview.
The tabmain.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>
And finally the manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.pack.thermostat"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="7" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".ThermostatTabHost"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
This example came straight of the android developers website (with a few minor changes), I also looked around for similar issues but I couldn't come up with anything.
Thank you in advance.
Upvotes: 0
Views: 274