0

I have been working on a game lately in MonoGame for Android and iOS and it has worked fine in the iOS simulator, but when I wanted to run it on my Android device, I get these 3 errors

/Users/edward/Library/Mobile Documents/com~apple~CloudDocs/apps/Xamarin/Android/Radiant/Android/Activity1.cs(10,10): Error CS0272: The property or indexer `Microsoft.Xna.Framework.Game.Activity' cannot be used in this context because the set accessor is inaccessible (CS0272) (Radiant.Droid)

/Users/edward/Library/Mobile Documents/com~apple~CloudDocs/apps/Xamarin/Android/Radiant/Android/Activity1.cs(4,4): Error CS1502: The best overloaded method match for `Android.App.Activity.SetContentView(Android.Views.View)' has some invalid arguments (CS1502) (Radiant.Droid)

/Users/edward/Library/Mobile Documents/com~apple~CloudDocs/apps/Xamarin/Android/Radiant/Android/Activity1.cs(21,21): Error CS1503: Argument `#1' cannot convert `Microsoft.Xna.Framework.GameWindow' expression to type `Android.Views.View' (CS1503) (Radiant.Droid)

EDIT: The relevant code is right here

public class Activity1 : AndroidGameActivity
{
    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        // Create our OpenGL view, and display it
        Game1.Activity = this;
        var g = new Game1();
        SetContentView(g.Window);
        g.Run();
    }

}
electrithm
  • 53
  • 6

1 Answers1

1

OK I was able to fix it by replacing it with this code

public class Activity1 : AndroidGameActivity
{
    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);
        var g = new Game1();
        SetContentView((View)g.Services.GetService(typeof(View)));
        g.Run();
    }
}
electrithm
  • 53
  • 6
  • This worked for me. Very surprised that this is still necessary even 9 months later. [MonoGame even talks about it in their documentation.](https://developer.xamarin.com/guides/cross-platform/game_development/monogame/introduction/part1/#Fixing_Android_Compile_Errors) – richkzad Apr 04 '17 at 06:30