New to Android and already stuck with the Tab Tutorial...


Last Updated:

  1. kivy

    kivy Member This Topic's Starter

    Joined:
    Jul 13, 2010
    Messages:
    17
    Likes Received:
    0
    Hi there, I am very new to Android and I have been working through various tutorials, so far everything's been fine until I started with the Android Tab Tutorial. I still have the "force close" error, even though I have tried several solutions that I found on the web. If someone could help me find where I am have done something wrong in my code, that would be absolutely fantastic. I am really getting desperate.

    So here is what I have done and thank you so much in advance...

    My [edited] Manifest.xml:

    Code (Text):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    3.       package="com.mobilevideoeditor.moved"
    4.       android:versionCode="1"
    5.       android:versionName="1.0">
    6.     <application android:icon="@drawable/icon" android:label="@string/app_name">
    7.           <activity android:name=".ShareGalleryView" android:label="@string/app_name"
    8.                       android:theme="@android:style/Theme.NoTitleBar"> </activity>
    9.                       <activity android:name=".EditGalleryView" android:label="@string/app_name"
    10.                   android:theme="@android:style/Theme.NoTitleBar"> </activity>  
    11.            <activity android:name=".GalleryView" android:label="@string/app_name"
    12.                   android:theme="@android:style/Theme.NoTitleBar">  
    13.             <intent-filter>
    14.                 <action android:name="android.intent.action.MAIN" />
    15.                 <category android:name="android.intent.category.LAUNCHER" />
    16.             </intent-filter>
    17.             <activity>
    18.        
    19.  
    20.     </application>
    21.  
    22.  
    23. </manifest>
    The main.xml:

    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>
    22.  
    The ic_tab_share.xml and ic_tab_edit.xml:

    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 ic_tab_share (grey icon) -->
    4.     <item android:drawable="@drawable/ic_tab_share"
    5.           android:state_selected="true" />
    6.     <!-- When not selected, use ic_tab_share_unselected (white icon)-->
    7.     <item android:drawable="@drawable/ic_tab_share_unselected" />
    8. </selector>
    The GalleryView.java file:

    Code (Text):
    1. package com.mobilevideoeditor.moved;
    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 GalleryView extends TabActivity {
    10.     /** Called when the activity is first created. */
    11.     @Override
    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;  // Reusable 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, EditGalleryView.class);
    23.  
    24.         // Initialize a TabSpec for each tab and add it to the TabHost
    25.         spec = tabHost.newTabSpec("edit").setIndicator("Edit",
    26.                           res.getDrawable(R.drawable.ic_tab_edit))
    27.                       .setContent(intent);
    28.         tabHost.addTab(spec);
    29.  
    30.         // Do the same for the other tabs
    31.         intent = new Intent().setClass(this, ShareGalleryView.class);
    32.         spec = tabHost.newTabSpec("share").setIndicator("Share",
    33.                           res.getDrawable(R.drawable.ic_tab_share))
    34.                           .setContent(intent);
    35.         tabHost.addTab(spec);
    36.  
    37.         tabHost.setCurrentTab(0);
    38.     }
    39. }
    and finally the ShareGalleryView.java and the EditGalleryView.java:

    Code (Text):
    1. package com.mobilevideoeditor.moved;
    2.  
    3. import android.app.Activity;
    4. import android.os.Bundle;
    5. import android.widget.TextView;
    6.  
    7.  
    8. public class EditGalleryView extends Activity {
    9.     public void onCreate(Bundle savedInstanceState) {
    10.         super.onCreate(savedInstanceState);
    11.  
    12.         TextView textview = new TextView(this);
    13.         textview.setText("This is the Edit tab!");
    14.         setContentView(textview);
    15.     }
    16. }
     

    Advertisement
  2. markb

    markb Well-Known Member

    Joined:
    Sep 14, 2009
    Messages:
    148
    Likes Received:
    26
    Hi kivy,

    There are 2 ways to start to investigate the problem, and they are well worth becoming familiar with.

    The first and simplest is to look at the logging output. That will give you an error message and stack trace which will tell you where it crashed. Quite often the cause will be obvious once you focus in the right area.

    If the logging isn't enough then the debugger can be a big help. You can step through the code until it crashes, examining variables as you go. Or if you know roughly where it crashes then you can set a breakpoint which will stop the program in the debugger.

    If you're still stumped after that then the log output will be useful as you can post it here, and it will help others to help you solve the problem.

    If you need pointers on how to look at the log output, and how to get started with the debugger then just ask.

    Mark
     
  3. kivy

    kivy Member This Topic's Starter

    Joined:
    Jul 13, 2010
    Messages:
    17
    Likes Received:
    0
    First of all I found what I did wrong :)

    I just looked at it I could understand some of it but I am not really comfortable with the debugger yet... :) but I think I'll get to it, thanks
     
  4. cp1

    cp1 Well-Known Member

    Joined:
    Apr 30, 2010
    Messages:
    375
    Likes Received:
    35
    Definitely check the logcat output in DDMS. It will tell you exactly what line your program crashed on.
     
  5. cam4mav

    cam4mav Member

    Joined:
    Jul 5, 2010
    Messages:
    22
    Likes Received:
    0
    Just wondering if you fixed it by adding the ShareGalleryView and the EditGalleryView activities to the manifest xml file?

    I had this same problem two days ago and found some suggestions on stack overflow, and adding the activity for each tab to the xml fixed it.

    Code (Text):
    1. <activity android:name=".AlbumsActivity"  android:label="@string/app_name"></activity>
    2. <activity android:name=".ArtistsActivity"  android:label="@string/app_name"></activity>
    3. <activity android:name=".SongsActivity"  android:label="@string/app_name"></activity>
     
  6. kivy

    kivy Member This Topic's Starter

    Joined:
    Jul 13, 2010
    Messages:
    17
    Likes Received:
    0
    No, I already had them in the manifest xml file, my problem was that I inserted them at the wrong location within the file.
     
  7. nikhilkilivayi

    nikhilkilivayi New Member

    Joined:
    Feb 10, 2011
    Messages:
    1
    Likes Received:
    0
    i hav same prblm....pls help ..
     

Share This Page

Loading...