We help IT Professionals succeed at work.

Application crashes with error

Anuradha Goli
Anuradha Goli used Ask the Experts™
on
I am new to Android programming.
When I create an application in Monodroid, it is not displayed in Emulator and the application is not responding.
please suggest me the ways to debug the error in the code in .net and other ebooks for better programming.
Looking at the code suggest me the corrections need to be done to view the app in emulator.
In the below code I am just displaying two tabs on the top.
namespace MonoAndroidApplication5
{
    [Activity(Label = "MonoAndroidApplication5", MainLauncher = true, Icon = "@drawable/icon")]
    public class Activity1 : Activity
    {
   
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.Main);

            TabHost tabHost = (TabHost)FindViewById(Resource.Id.widget35);
            tabHost.Setup();         

            TabHost.TabSpec spec1 = tabHost.NewTabSpec("Tab 1");
            Intent in1 = new Intent("Tab1");
            spec1.SetContent(in1);

            TabHost.TabSpec spec2 = tabHost.NewTabSpec("Tab 2");
            Intent in2 = new Intent("Tab2");
            spec2.SetContent(in2);

            tabHost.AddTab(spec1);
            tabHost.AddTab(spec1);
        }
    }
}

Open in new window

<?xml version="1.0" encoding="utf-8"?>
<TabHost
	android:id="@android:id/tabhost"
	android:layout_width="fill_parent"
	android:layout_height="fill_parent"
	xmlns:android="http://schemas.android.com/apk/res/android">
  <LinearLayout
    android:id="@+id/widget35"
    android:layout_width="320px"
    android:layout_height="149px">
    <TabWidget
      android:id="@android:id/tabs"
      android:layout_width="105px"
      android:layout_height="wrap_content" />
    <TabWidget
      android:id="@android:id/tabs"
      android:layout_width="105px"
      android:layout_height="wrap_content" />
    <TabWidget
      android:id="@android:id/tabs"
      android:layout_width="110px"
      android:layout_height="wrap_content"
      android:layout_gravity="center_horizontal" />
  </LinearLayout>
</TabHost>

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Technical Lead
Commented:
Hi,

From the android docs ...

1) public TabHost.TabSpec setContent (int viewId)
Since: API Level 1 Specify the id of the view that should be used as the content of the tab.

Example :
mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator("TAB 1").setContent(R.id.textview1));

2) public TabHost.TabSpec setContent (Intent intent)
Since: API Level 1 Specify an intent to use to launch an activity as the tab content.

3) public TabHost.TabSpec setContent (TabHost.TabContentFactory contentFactory)
Since: API Level 1 Specify a TabHost.TabContentFactory to use to create the content of the tab.

Example :

TabSpec setContent = mTabHost.newTabSpec(tag)
                                                   .setIndicator(aTabview)
                                                   .setContent(new TabContentFactory() {
                                                              public View createTabContent(String tag)  {
                                                                         return view;
                                                               }  
                                                   });  


A)
In your code snippet you are setting some thing like this
Intent in2 = new Intent("Tab2");
spec2.SetContent(in2);

Here it will try to launch the activity as the tab content..But It is not having any activity info (Neither as Exceplicit nor Implicit intent)

B)
In your Xml layout file you didn't give any ViewGroup for Tab Content.....
Some think like this you need to create a view inside your XML file...

                <FrameLayout            
                            adroid:id="@android:id/tabcontent"
                            android:layout_width="fill_parent"
                            android:layout_height="fill_parent">


Refer this links for more information
http://developer.android.com/guide/tutorials/views/hello-tabwidget.html
http://joshclemm.com/blog/?p=136
http://dewful.com/?p=15
Anuradha GoliSystems Development / Support Specialist

Author

Commented:
Can you suggest me how to learn monodroid , i started installation and implemented hello world program, what next i need to proceed to create app