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

Apps HELP! : HelloTabWidget Tutorial on Android Developers site FORCE CLOSE

Discussion in 'Android Development' started by 4ndr01d61r7, Apr 30, 2012.

  1. 4ndr01d61r7

    4ndr01d61r7 Lurker
    Thread Starter
    Rank:
    None
    Points:
    25
    Posts:
    3
    Joined:
    Apr 30, 2012

    Apr 30, 2012
    3
    0
    25
    Software Engineer
    I am an Android developer amateur and I went to Android Developers site to learn more about Android development. I completed the previous tutorials and I am now in Tab Layout. When I got to run the program. It says FORCE CLOSE. I don't know where part of the program I did wrong. The tutorial site never gave in depth description of the code and there were missing blocks which I found out by surfing over the net. I know there are some who has the same problem as mine. I hope this will be solved soon for me to be able to proceed to the next chapter. Thank you in advance.

    Here is my code :
    src folder :
    - com dot android dot HelloTabWidget
    - comdotandroiddotHelloTabWidget/HelloTabWidgetActivitydotjava

    Code (Text):
    1. package com.android.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.util.Log;
    8. import android.widget.TabHost;
    9.  
    10. public class HelloTabWidgetActivity extends TabActivity  {
    11.  
    12. private String TAG="HelloTabWidget";
    13.  
    14. public void onCreate(Bundle savedInstanceState) {
    15.   super.onCreate(savedInstanceState);
    16.   setContentView(R.layout.main);
    17.  
    18.   Resources res = getResources(); // Resource object to get Drawables
    19.   TabHost tabHost = getTabHost();  // The activity TabHost
    20.   TabHost.TabSpec spec;  // Resusable TabSpec for each tab
    21.   Intent intent;  // Reusable Intent for each tab
    22.  
    23.   // Create an Intent to launch an Activity for the tab (to be reused)
    24.   intent = new Intent().setClass(this,ArtistsActivity.class);
    25.   Log.v(TAG,"---artist activity is called---");
    26.  
    27.   // Initialize a TabSpec for each tab and add it to the TabHost
    28.   spec = tabHost.newTabSpec("artists").setIndicator("Artists",res.getDrawable(R.drawable.ic_tab_artists)).setContent(intent);
    29.   tabHost.addTab(spec);
    30.  
    31.  
    32.   // Do the same for the other tabs
    33.   intent = new Intent().setClass(this,AlbumsActivity.class);
    34.   Log.v(TAG,"---album activity is called---");
    35.   spec = tabHost.newTabSpec("albums").setIndicator("Albums",res.getDrawable(R.drawable.ic_tab_albums)).setContent(intent);
    36.   tabHost.addTab(spec);
    37.  
    38.   intent = new Intent().setClass(this, SongsActivity.class);
    39.   Log.v(TAG,"---song activity is called---");
    40.   spec = tabHost.newTabSpec("songs").setIndicator("Songs",res.getDrawable(R.drawable.ic_tab_songs)).setContent(intent);
    41.   tabHost.addTab(spec);
    42.  
    43.   }
    44.  
    45. }
    - /src/comdotandroiddotHelloTabWidget/AlbumsActivitydotjava
    Code (Text):
    1. package com.android.HelloTabWidget;
    2.  
    3. import android.app.Activity;
    4. import android.os.Bundle;
    5. import android.util.Log;
    6. import android.widget.TextView;
    7.  
    8. public class AlbumsActivity extends Activity{
    9.     private String TAG="AlbumsActivity";
    10.     @Override
    11.     public void onCreate(Bundle savedInstance)
    12.     {
    13.         super.onCreate(savedInstance);
    14.         TextView textview_album=new TextView(this);
    15.         textview_album.setText("This is album activity");
    16.         setContentView(textview_album);
    17.         Log.v(TAG,"---in album activity---");
    18.     }
    19.  
    20. }
    - /src/comdotandroiddotHelloTabWidget/ArtistsActivitydotjava
    Code (Text):
    1. package com.android.HelloTabWidget;
    2.  
    3. import android.app.Activity;
    4. import android.os.Bundle;
    5. import android.util.Log;
    6. import android.widget.TextView;
    7.  
    8. public class ArtistsActivity extends Activity {
    9.  private String TAG="ArtistsActivity";
    10.     /** Called when the activity is first created. */
    11.     @Override
    12.       public void onCreate(Bundle savedInstanceState) {
    13.         super.onCreate(savedInstanceState);
    14.         TextView textview=new TextView(this);
    15.         textview.setText("This is Artist Activity");
    16.         setContentView(textview);
    17.         Log.v(TAG,"---in artist activity---");
    18.     }
    19. }
    - /src/comdotandroiddotHelloTabWidget/SongsActivitydotjava
    Code (Text):
    1. package com.android.HelloTabWidget;
    2.  
    3. import android.app.Activity;
    4. import android.os.Bundle;
    5. import android.util.Log;
    6. import android.widget.TextView;
    7.  
    8. public class SongsActivity extends Activity{
    9.     private String TAG="SongsActivity";
    10.     @Override
    11.     public void onCreate(Bundle savedInstance)
    12.     {
    13.         super.onCreate(savedInstance);
    14.         TextView textview_song=new TextView(this);
    15.         textview_song.setText("This is song activity");
    16.         setContentView(textview_song);
    17.         Log.v(TAG,"---in songs activity---");
    18.     }
    19.  
    20. }
    - /res/drawable/ic_tabs_albumsdotxml
    Code (Text):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <selector xmlns:android="http://schemas.android.com/apk/res/android">
    3.     <!-- When selected, use grey -->
    4.     <item android:drawable="@drawable/ic_tab_albums_grey"
    5.           android:state_selected="true" />
    6.     <!-- When not selected, use white-->
    7.     <item android:drawable="@drawable/ic_tab_albums_white" />
    8. </selector>
    - /res/drawable/ic_tabs_artistsdotxml
    Code (Text):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <selector xmlns:android="http://schemas.android.com/apk/res/android">
    3.     <!-- When selected, use grey -->
    4.     <item android:drawable="@drawable/ic_tab_artists_grey"
    5.           android:state_selected="true" />
    6.     <!-- When not selected, use white-->
    7.     <item android:drawable="@drawable/ic_tab_artists_white" />
    8. </selector>
    - /res/drawable/ic_tabs_songsdotxml
    Code (Text):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <selector xmlns:android="http://schemas.android.com/apk/res/android">
    3.     <!-- When selected, use grey -->
    4.     <item android:drawable="@drawable/ic_tab_songs_grey"
    5.           android:state_selected="true" />
    6.     <!-- When not selected, use white-->
    7.     <item android:drawable="@drawable/ic_tab_songs_white" />
    8. </selector>
    - /layout/maindotxml
    Code (Text):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    3.     android:id="@android:id/tabhost"
    4.     android:layout_width="fill_parent"
    5.     android:layout_height="fill_parent">
    6.     <LinearLayout
    7.         android:orientation="vertical"
    8.         android:layout_width="fill_parent"
    9.         android:layout_height="fill_parent"
    10.         android:padding="5dp">
    11.         <TabWidget
    12.             android:id="@android:id/tabs"
    13.             android:layout_width="fill_parent"
    14.             android:layout_height="wrap_content" />
    15.         <FrameLayout
    16.             android:id="@android:id/tabcontent"
    17.             android:layout_width="fill_parent"
    18.             android:layout_height="fill_parent"
    19.             android:padding="5dp" />
    20.     </LinearLayout>
    21. </TabHost>
    AndroidManifestdotxml
    Code (Text):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    3.       package="com.android.HelloTabWidget"
    4.       android:versionCode="1"
    5.       android:versionName="1.0">
    6.      
    7.    <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="8"/>
    8.    
    9.     <application android:icon="@drawable/ic_launcher"  android:label="@string/app_name">
    10.        <activity android:name=".HelloTabWidget" android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar" >
    11.           <intent-filter>
    12.                 <action android:name="android.intent.action.MAIN" />
    13.                  <category android:name="android.intent.category.LAUNCHER" />
    14.           </intent-filter>
    15.        </activity>
    16.        <activity android:name=".AlbumsActivity" android:label="@string/app_name"></activity>
    17.        <activity android:name=".ArtistsActivity" android:label="@string/app_name"></activity>  
    18.        <activity android:name=".SongsActivity" android:label="@string/app_name" ></activity>
    19.     </application>
    20. </manifest>
     

    Advertisement

Share This Page

Loading...