question

FransPinos-2068 avatar image
0 Votes"
FransPinos-2068 asked ·

Xamarin Android Multiple Activity error: System.MemberAccessException

After experience spinner problems at the time to add more than 4 Activity in my main App (Xamarin Android) I builded one very simple App with the minimum minimum in order to play with spinners.
This test App is like the following:

MainActivity has only one Button that transfers to Activity1. In MainActivity there's no code, only the button:

namespace App2
{
[Activity(Label = "@string/app_name", Theme = "@style/AppTheme", MainLauncher = true)]
public class MainActivity : AppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.activity_main);

         Button Btn_1 = FindViewById<Button>(Resource.Id.button1);
         Btn_1.Click += delegate
         {
             StartActivity(typeof(Activity1));
         };
 }
 }

}

Activity1 has only the code corresponding to the Spinner. Nothing else.

namespace App2
{
[Activity(Label = "Activity1")]
public class Activity1 : Activity
{
private static Spinner N_Filter;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);

         SetContentView(Resource.Layout.layout1);
         // Create your application here
         N_Filter = (Spinner)FindViewById(Resource.Id.nfiltros);

         //- Definición Spinner Número de Filtros
         N_Filter.ItemSelected += new EventHandler<AdapterView.ItemSelectedEventArgs>(N_Filter_ItemSelected);
         var adapter = ArrayAdapter.CreateFromResource(this, Resource.Array.Num_1a24, Android.Resource.Layout.SimpleSpinnerItem);
         adapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
         N_Filter.Adapter = adapter;
     }
     private void N_Filter_ItemSelected(object sender, AdapterView.ItemSelectedEventArgs e)
     {
         int Xi = e.Position;

         Xi = Xi * 2;
     }
 }

}

All the rest of the Activity2...4 are only empty activities add automatically Like:

namespace App2
{
[Activity(Label = "Activity3")]
public class Activity3 : Activity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);

         // Create your application here
     }
 }

}

At the time of add Activity 4 is when the following errors occurs: In line:
var adapter = ArrayAdapter.CreateFromResource(this, Resource.Array.Num_1a24, Android.Resource.Layout.SimpleSpinnerItem);

Exception error: System.MemberAccessException: 'Cannot create an instance of Android.Widget.ArrayAdapter`1[T] because Type.ContainsGenericParameters is true.'

And IF I REMOVE Activity4 the App WORKS again WITH NO ISSUE. If I add it again it fails...

Note: Num_1a24 is one string-array on strings.xml.

not-supported
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

RichardZhang-MSFT avatar image
0 Votes"
RichardZhang-MSFT answered ·

Hello,

Welcome to Microsoft Q&A!

Q&A will add more product support in the future, you can view the current product support list here: Supported products

Your question about Xamarin.Android is not supported right now. But there is a better place for asking questions about this, you could ask about this question in Xamarin.Android forums.

Thank you.

·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.