Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid TabLayout crashing
    primarykey
    data
    text
    <p>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.</p> <p>ThermostatTabHost.java (note, I did not add package/import to save some space):</p> <pre><code>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); } } </code></pre> <p>The ThermostatActvity class currently only holds a onCreate function which calls super.onCreate(savedInstance) and sets a layout with a textview.</p> <p>The tabmain.xml file:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;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"&gt; &lt;LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="5dp"&gt; &lt;TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" /&gt; &lt;FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="5dp" /&gt; &lt;/LinearLayout&gt; &lt;/TabHost&gt; </code></pre> <p>And finally the manifest file:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.pack.thermostat" android:versionCode="1" android:versionName="1.0" &gt; &lt;uses-sdk android:minSdkVersion="7" /&gt; &lt;application android:icon="@drawable/ic_launcher" android:label="@string/app_name" &gt; &lt;activity android:name=".ThermostatTabHost" android:label="@string/app_name" &gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;/application&gt; &lt;/manifest&gt; </code></pre> <p>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.</p> <p>Thank you in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload