1

I've always used Xcode in the past so now I'm trying to learn Android and I'm using Eclipse

I followed all the steps outlined in http://developer.android.com/resources/tutorials/views/hello-tabwidget.html but when I actually run the code on my LG Revolution (Froyo 2.2.1), I am crashing.

I'm not sure how to debug but I don't know why this would even crash. Any help would be appreciated.

I used the same image for all 3 tabs (thats the only modification I made but I don't think it should crash)

Here is my code

package com.oneorangetree.shit;

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

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

        // Resource object to get drawable
        Resources res = getResources();
        TabHost tabHost = getTabHost();
        TabHost.TabSpec spec;
        Intent intent;

        intent = new Intent().setClass(this, ArtistsActivity.class);
        spec = tabHost.newTabSpec("artists").setIndicator("Artists", res.getDrawable(R.drawable.ic_tab_artists)).setContent(intent);
        tabHost.addTab(spec);

        intent = new Intent().setClass(this, AlbumsActivity.class);
        spec = tabHost.newTabSpec("albums").setIndicator("Albums", res.getDrawable(R.drawable.ic_tab_artists)).setContent(intent);
        tabHost.addTab(spec);

        intent = new Intent().setClass(this, SongsActivity.class);
        spec = tabHost.newTabSpec("songs").setIndicator("Songs", res.getDrawable(R.drawable.ic_tab_artists)).setContent(intent);
        tabHost.addTab(spec);

        tabHost.setCurrentTab(2);
    }
}

here is my Manifest file

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.oneorangetree.shit"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="8" />

    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".HelloTabWidgetActivity"
                  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>
ming_codes
  • 2,870
  • 25
  • 24
Cocoa Dev
  • 9,361
  • 31
  • 109
  • 177
  • 3
    I can guarantee that you will get no answers until you post some code. – Peaches491 Aug 15 '11 at 18:52
  • 2
    The best way to find a crash is checking the LogCat. That is basically androids system log. You can find it in either the ddms application in your `SDK/tools` folder or in eclipse via `Window->Add view->other->LogCat`. There should be an exception in there (printed in red with the tag AndroidRuntime). After you have it, post it and add the relevant piece of code please. –  Aug 15 '11 at 18:54
  • The answers to my question will answer this for you http://stackoverflow.com/questions/2209406/issues-with-android-tabhost-example – KevinDTimm Aug 15 '11 at 18:55
  • IOW, the example is not complete - find the answer that describes how to complete it and you will be up and running – KevinDTimm Aug 15 '11 at 19:06
  • @KevinDTimm - you maybe right. Can you post your Manifest file as an answer so then I can accept it and give you cred? – Cocoa Dev Aug 15 '11 at 19:21
  • @Cocoa - see below (but don't vote or accept, just follow the instructions given in the answer by `Ted` in my original query – KevinDTimm Aug 15 '11 at 19:25

2 Answers2

1

Wild guess : did you add all of your activities into the manifest ? One activity equals one mention in the manifest.

When you create a projet your main activity is by default added to this file so the system know that is it ok to launch your main activity. Now, each time you add a new activity in your project you had to add this activity in the manifest :

<activity android:name=".HelloTabWidget" android:label="@string/app_name"
      android:theme="@android:style/Theme.NoTitleBar">

If it is not that you add some break points by clicking on the left margin of your file then click on the debug button. Finally you open the debug perspective, and you navigate between your break points with F8.

Hope it helps, been there too :).

mthpvg
  • 3,789
  • 3
  • 26
  • 34
1

See the information in http://code.google.com/p/android/issues/detail?id=4183 and implement the fixes by Ted in my original question - below is the manifest but there are other errors too:

<activity android:name=".AlbumsActivity"
          android:label="@string/app_name"
          android:theme="@android:style/Theme.NoTitleBar">
</activity>
<activity android:name=".ArtistsActivity"
          android:label="@string/app_name"
          android:theme="@android:style/Theme.NoTitleBar">
</activity>
<activity android:name=".SongsActivity"
          android:label="@string/app_name"
          android:theme="@android:style/Theme.NoTitleBar">
</activity>
KevinDTimm
  • 14,226
  • 3
  • 42
  • 60