Click here to Skip to main content
15,885,782 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i'm very new to Android development.

In my MainActivity.cs file, I've declared an OnOptionsItemSelected(IMenuItem item) method that allows the user to jump between the current MainActivity.cspage and another page I created called Settings.cs. When i select a option i'm getting

System.NullReferenceException: Object reference not set to an instance of an object

Any idea
Posted
Updated 21-Oct-14 0:51am
v2
Comments
Richard Deeming 21-Oct-14 8:28am    
You're trying to call a method or access a property on an object which has not been initialized.

Since you haven't posted any code, we can't tell you any more than that.
Maddy Mc 21-Oct-14 9:13am    
public class Activity1 : Activity
{

protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);

// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
}

public override bool OnCreateOptionsMenu(IMenu menu)
{
var inflater = MenuInflater;
inflater.Inflate(Resource.Menu.option_menu, menu);
return base.OnPrepareOptionsMenu(menu);
}


public override bool OnOptionsItemSelected(IMenuItem item)
{
var intent = new Intent(this, typeof(APR_Edit));

switch (item.ItemId)
{
case Resource.Id.item1: Toast.MakeText(this, " WORKING", ToastLength.Long).Show();


return true;



case Resource.Id.item2: Toast.MakeText(this, "DISCOVER WORKING", ToastLength.Long).Show();
StartActivity(typeof(Activity2));// Want to start this activity on item2 selection


return true;

case Resource.Id.Advance: var intent = new Intent(this, typeof(Activity3));
try
{
StartActivity(intent);
}
catch (NullReferenceException ex)
{
string sMessage = ex.Message;
Toast.MakeText(this, sMessage, ToastLength.Long).Show();

}
return true;

case Resource.Id.Close: Android.OS.Process.KillProcess(Android.OS.Process.MyPid());
return true;
}
return base.OnOptionsItemSelected(item);
}

i've tried two different method to start another activity
can you help me on this

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900