[Mono-bugs] [Bug 679789] mono-android-9794 -the application crash and i have runtime Exception of type ‘Java .Lang. NullPointerException’ was thrown .
bugzilla_noreply at novell.com
bugzilla_noreply at novell.com
Wed Mar 16 11:00:19 EDT 2011
https://bugzilla.novell.com/show_bug.cgi?id=679789
https://bugzilla.novell.com/show_bug.cgi?id=679789#c1
Jonathan Pryor <jpryor at novell.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |CLOSED
CC| |jpryor at novell.com
Resolution| |INVALID
--- Comment #1 from Jonathan Pryor <jpryor at novell.com> 2011-03-16 15:00:18 UTC ---
My guess is that you changed the code between then and now.
There are two ways (at least) to make this work.
Way 1: Don't inherit from Android.App.Activity, but instead
Android.App.TabActivity, as discussed in the TabActivity tutorial:
http://mono-android.net/Tutorials/Hello_Views/Tab_Layout
Then, DO NOT create a new TabHost instance (as you did), but instead use the
TabActivity.TabHost property:
// within a TabActivity subclass...
protected override void OnCreate (Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
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
intent = new Intent(this, typeof(MyHelloView));
intent.AddFlags(ActivityFlags.NewTask);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = TabHost.NewTabSpec("MyHelloView");
spec.SetIndicator("Hello",
Resources.GetDrawable(Resource.Drawable.Icon));
spec.SetContent(intent);
TabHost.AddTab(spec);
}
Way 2: Inherit from ActivityGroup, lookup the TabHost instance using
FindViewById(), and Setup the TabHost instance, as is required by the
documentation:
http://developer.android.com/reference/android/widget/TabHost.html#setup(android.app.LocalActivityManager)
You'll want to inherit from ActivityGroup so you have access to the
LocalActivityManager property:
[Activity (Label = "TabHost Bug?", MainLauncher = true)]
public class Activity1 : ActivityGroup
{
protected override void OnCreate (Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
TabHost TabHost =
FindViewById<TabHost>(Android.Resource.Id.TabHost);
TabHost.Setup(LocalActivityManager);
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
intent = new Intent(this, typeof(MyHelloView));
intent.AddFlags(ActivityFlags.NewTask);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = TabHost.NewTabSpec("MyHelloView");
spec.SetIndicator("Hello",
Resources.GetDrawable(Resource.Drawable.Icon));
spec.SetContent(intent);
TabHost.AddTab(spec);
}
}
Either of these mechanisms work for me, though inheriting from TabActivity
seems to be the easier way.
--
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
More information about the mono-bugs
mailing list