1. Download our Official Android App: Forums for Android!

Apps HelloTabWidget Tutorial Problems

Discussion in 'Android Development' started by aSystemOverloa, Jan 7, 2012.

  1. aSystemOverloa

    Thread Starter
    Rank:
    None
    Points:
    16
    Posts:
    52
    Joined:
    May 12, 2011

    May 12, 2011
    52
    6
    16
    I've spent a while going through the posts on here, stack overflow and elsewhere about this, but can't seem to get the HelloTabWidget tutorial to work.

    As below, it won't run, say it has errors [AlbumsActivity cannot be resolved into a type.] and suggests adding [import superiorxc.examples.AlbumsActivity.AlbumsActivity;] for each Albums, Songs and ArtistsActivity, but this causes a ForceClosure when it runs (ERROR: [01-07 18:15:03.230: E/AndroidRuntime(326): java.lang.RuntimeException: Unable to start activity ComponentInfo{superiorxc.examples.hellotabwidget/superiorxc.examples.hellotabwidget.HelloTabWidgetActivity}: android.content.ActivityNotFoundException: Unable to find explicit activity class {superiorxc.examples.hellotabwidget/superiorxc.examples.ArtistsActivity.ArtistsActivity}; have you declared this activity in your AndroidManifest.xml?]).

    Would appreciate any feedback:

    HelloTabWidget.java

    Code (Text):
    1. package superiorxc.examples.hellotabwidget;
    2.  
    3. import android.app.TabActivity;
    4. import android.content.Intent;
    5. import android.content.res.Resources;
    6. import android.os.Bundle;
    7. import android.widget.TabHost;
    8.  
    9. public class HelloTabWidgetActivity extends TabActivity {
    10.     /** Called when the activity is first created. */
    11.    
    12.     public void onCreate(Bundle savedInstanceState) {
    13.         super.onCreate(savedInstanceState);
    14.         setContentView(R.layout.main);
    15.  
    16.         Resources res = getResources(); // Resource object to get Drawables
    17.         TabHost tabHost = getTabHost();  // The activity TabHost
    18.         TabHost.TabSpec spec;  // Resusable TabSpec for each tab
    19.         Intent intent;  // Reusable Intent for each tab
    20.  
    21.         // Create an Intent to launch an Activity for the tab (to be reused)
    22.         intent = new Intent().setClass(this, ArtistsActivity.class);
    23.  
    24.         // Initialize a TabSpec for each tab and add it to the TabHost
    25.         spec = tabHost.newTabSpec("artists").setIndicator("Artists",
    26.                           res.getDrawable(R.drawable.ic_tab_artists))
    27.                       .setContent(intent);
    28.         tabHost.addTab(spec);
    29.  
    30.         // Do the same for the other tabs
    31.         intent = new Intent().setClass(this, AlbumsActivity.class);
    32.         spec = tabHost.newTabSpec("albums").setIndicator("Albums",
    33.                           res.getDrawable(R.drawable.ic_tab_albums))
    34.                       .setContent(intent);
    35.         tabHost.addTab(spec);
    36.  
    37.         intent = new Intent().setClass(this, SongsActivity.class);
    38.         spec = tabHost.newTabSpec("songs").setIndicator("Songs",
    39.                           res.getDrawable(R.drawable.ic_tab_songs))
    40.                       .setContent(intent);
    41.         tabHost.addTab(spec);
    42.  
    43.         tabHost.setCurrentTab(2);
    44.     }
    45. }
    AlbumsActivity.java (+ ArtistsACtivity, SongsACtivity)

    Code (Text):
    1. package superiorxc.examples.AlbumsActivity;
    2.  
    3. import android.app.Activity;
    4. import android.os.Bundle;
    5. import android.widget.TextView;
    6.  
    7. public class AlbumsActivity extends Activity {
    8.     public void onCreate(Bundle savedInstanceState) {
    9.         super.onCreate(savedInstanceState);
    10.  
    11.         TextView textview = new TextView(this);
    12.         textview.setText("This is the Albums tab");
    13.         setContentView(textview);
    14.     }
    15. }
    HelloTabWidget Manifest:
    Code (Text):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    3.     package="superiorxc.examples.hellotabwidget"
    4.     android:versionCode="1"
    5.     android:versionName="1.0" >
    6.  
    7.     <uses-sdk android:minSdkVersion="8" />
    8.  
    9.     <application
    10.         android:icon="@drawable/ic_launcher"
    11.         android:label="@string/app_name" >
    12.         <activity
    13.             android:label="@string/app_name"
    14.             android:name=".HelloTabWidgetActivity" >
    15.         <intent-filter >
    16.         <action android:name="android.intent.action.MAIN" />
    17.         <category android:name="android.intent.category.LAUNCHER" />
    18.         </intent-filter>
    19.         </activity>
    20.         <activity android:name=".AlbumsActivity"
    21.             android:label="@string/app_name"
    22.             android:theme="@android:style/Theme.NoTitleBar">
    23.          </activity>
    24.          <activity android:name=".ArtistsActivity"
    25.             android:label="@string/app_name"
    26.             android:theme="@android:style/Theme.NoTitleBar">
    27.             </activity>
    28.          <activity android:name=".SongsActivity"
    29.              android:label="@string/app_name"
    30.             android:theme="@android:style/Theme.NoTitleBar">
    31.         </activity>
    32.     </application>
    33. </manifest>
     

    Advertisement

  2. aSystemOverloa

    Thread Starter
    Rank:
    None
    Points:
    16
    Posts:
    52
    Joined:
    May 12, 2011

    May 12, 2011
    52
    6
    16
    Anyone have any ideas?
     

Share This Page

Loading...