0

I am trying to launch a tabActivity from the menu pane of my main activity (i mean the one that loads on startup).

Although the app compiles fine , and even runs, as soon as I press the menu button then the relevant icon for the tabActivity there is a runtime error:

$ 04-10 03:00:50.374: E/AndroidRuntime(6531): FATAL EXCEPTION: main
04-10 03:00:50.374: E/AndroidRuntime(6531): java.lang.RuntimeException: Unable to start activity ComponentInfo{Impek.Gen/Impek.Gen.Impekcals}: java.lang.RuntimeException: Your content must have a TabHost whose id attribute is 'android.R.id.tabhost'
04-10 03:00:50.374: E/AndroidRuntime(6531):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2753)
04-10 03:00:50.374: E/AndroidRuntime(6531):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2769)
04-10 03:00:50.374: E/AndroidRuntime(6531):     at android.app.ActivityThread.access$2500(ActivityThread.java:129)
04-10 03:00:50.374: E/AndroidRuntime(6531):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2117)
04-10 03:00:50.374: E/AndroidRuntime(6531):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-10 03:00:50.374: E/AndroidRuntime(6531):     at android.os.Looper.loop(Looper.java:143)
04-10 03:00:50.374: E/AndroidRuntime(6531):     at android.app.ActivityThread.main(ActivityThread.java:4717)
04-10 03:00:50.374: E/AndroidRuntime(6531):     at java.lang.reflect.Method.invokeNative(Native Method)
04-10 03:00:50.374: E/AndroidRuntime(6531):     at java.lang.reflect.Method.invoke(Method.java:521)
04-10 03:00:50.374: E/AndroidRuntime(6531):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
04-10 03:00:50.374: E/AndroidRuntime(6531):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
04-10 03:00:50.374: E/AndroidRuntime(6531):     at dalvik.system.NativeStart.main(Native Method)
04-10 03:00:50.374: E/AndroidRuntime(6531): Caused by: java.lang.RuntimeException: Your content must have a TabHost whose id attribute is 'android.R.id.tabhost'
04-10 03:00:50.374: E/AndroidRuntime(6531):     at android.app.TabActivity.onContentChanged(TabActivity.java:105)
04-10 03:00:50.374: E/AndroidRuntime(6531):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:229)
04-10 03:00:50.374: E/AndroidRuntime(6531):     at android.app.Activity.setContentView(Activity.java:1677)
04-10 03:00:50.374: E/AndroidRuntime(6531):     at Impek.Gen.Impekcals.onCreate(Impekcals.java:34)
04-10 03:00:50.374: E/AndroidRuntime(6531):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-10 03:00:50.374: E/AndroidRuntime(6531):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2717)
04-10 03:00:50.374: E/AndroidRuntime(6531):     ... 11 more

Code:

     $  main activitys oncreate and menu functions
     public class ImpekActivity extends Activity {
/** Called when the activity is first created. */
private Planner p;
public static Context curr;
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    curr = this;
    GeoLocation.setup_GeoLocation();
    p = new Planner(curr);
    update();
    //p.addNewEntry("", latitude, longitude, arrival, postcode)
} 

        @Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle item selection
    switch (item.getItemId()) {
        case R.id.item2:
            Intent f = new Intent(curr, Impeksettings.class);
            startActivity(f);
            return true;
        case R.id.item1:
            Intent t = new Intent(curr,Impekadd.class);
            startActivity(t);
            return true;
        case R.id.calendars:
            Intent c = new Intent(curr,Impekcals.class);
            startActivity(c);
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.mainmenu, menu);
    return true;
}`

This tab activity is called on press:

public class Impekcals extends TabActivity{

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.calendars);

            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, GlobalCal.class);

            // Initialize a TabSpec for each tab and add it to the TabHost
            spec = tabHost.newTabSpec("global").setIndicator("Global",
                              res.getDrawable(R.drawable.globalcal))
                          .setContent(intent);
            tabHost.addTab(spec);

            // Do the same for the other tabs
            intent = new Intent().setClass(this, GoogleCal.class);
            spec = tabHost.newTabSpec("Googlecal").setIndicator("Google",
                              res.getDrawable(R.drawable.googlecal))
                          .setContent(intent);
            tabHost.addTab(spec);

            intent = new Intent().setClass(this, LocalCal.class);
            spec = tabHost.newTabSpec("Local").setIndicator("Local",
                              res.getDrawable(R.drawable.localcal))
                          .setContent(intent);
            tabHost.addTab(spec);


            intent = new Intent().setClass(this, SearchEvent.class);
            spec = tabHost.newTabSpec("search").setIndicator("Search",
                              res.getDrawable(R.drawable.searchcal))
                          .setContent(intent);
            tabHost.addTab(spec);

     tabHost.setCurrentTab(1);

    }



}




    `

Any help appreciated :D

Houssem El Fekih
  • 230
  • 3
  • 11

1 Answers1

0

I wonder if either this question or this one addresses your problem?

Without the source code, and in particular to see if you have:

setContentView(R.layout.main);

or

setContentView(R.layout.your_resource_id);

it is difficult to provide any further help.

Community
  • 1
  • 1
Ken Y-N
  • 14,644
  • 21
  • 71
  • 114
  • I have edited my question to include some relevant code .. tell me if anything else is needed .. i have tried both the fixes from your links none being successful .. thanks for your time – Houssem El Fekih Apr 10 '12 at 02:58
  • Turns out deleting the setContentview line completely fixes it .. but why? Is it definitely a problem with the xml? Anyways thanks very much .. i know what the error is now so i can work on it .. :D – Houssem El Fekih Apr 10 '12 at 04:27
  • Okay defintely fixed. very silly mistake from my part in the specification of the xml version in the file .. Thanks very much for your time and suggestions – Houssem El Fekih Apr 10 '12 at 17:42