Skip to content
This repository has been archived by the owner on Mar 24, 2023. It is now read-only.

Xamarin.Forms[Android] app crashing with Annotations #88

Open
andreybel opened this issue Jul 17, 2020 · 2 comments
Open

Xamarin.Forms[Android] app crashing with Annotations #88

andreybel opened this issue Jul 17, 2020 · 2 comments

Comments

@andreybel
Copy link

Hi!
I'm trying to implement Mapbox in my Xamarin.Forms app and have a problem.
When i'm adding List of Annotations to Map and restart app, i'm getting Exception:

java.lang.NullPointerException: Attempt to invoke virtual method 'android.graphics.Bitmap$Config android.graphics.Bitmap.getConfig()' on a null object reference

My Annotation:
Annotations.Add(new SymbolAnnotation
{
Coordinates = new LatLng(50.4308233, 30.468171),
Id = Guid.NewGuid().ToString(),
Title = "test point",
SubTitle = "test point description",
IconImage = (ImageSource)"ic_pin8.png", // problem is here
IsDraggable = false
});

NOTE: It doesn't happen during first start, only after OnSleep() - OnResume().
Tell me please, where is my mistake?
Thank's!

P.S. problem detected on Android

@tuyen-vuduc
Copy link
Contributor

Hy @andreybel ,

Could you share a code sample for the issue?

Cheers.

@andreybel
Copy link
Author

andreybel commented Jul 17, 2020

Here is my code sample.
I'm using Prism MVVM in my project.

**MapPage.xaml**

 <mapbox:MapView
                x:Name="map" 
                      Grid.Row="0"
                      Grid.RowSpan="5"
                      ShowUserLocation="True"
                      DidFinishLoadingStyleCommand="{Binding DidFinishLoadingStyleCommand}"
                      DidTapOnMarkerCommand="{Binding DidTapOnMarkerCommand}"
                      VerticalOptions="FillAndExpand"
                      HorizontalOptions="Fill"/>


**MapPage.xaml.cs**

public partial class MapPage : ContentPage
{
        public MapPage()
        {
            InitializeComponent();
            map.Center = new LatLng(50.4308233, 30.468171);
            map.ZoomLevel = 12;
            map.Pitch = 60;
            map.MapStyle = MapStyle.STREETS;

        }
}


**MapPageViewModel.cs**

private ObservableCollection<Annotation> _annotations;
        public ObservableCollection<Annotation> Annotations
        {
            get => _annotations;
            set => SetProperty(ref _annotations, value);
        }

private DelegateCommand<MapStyle> _didFinishLoadingStyleCommand;
        public DelegateCommand<MapStyle> DidFinishLoadingStyleCommand => (_didFinishLoadingStyleCommand 
            ?? (_didFinishLoadingStyleCommand = new DelegateCommand<MapStyle>(OnDidFinishLoadingStyle)));

        private void OnDidFinishLoadingStyle(MapStyle style)
        {
            try
            {
                Annotations = new ObservableCollection<Annotation>();
                Annotations.Add(new SymbolAnnotation
                {
                    Coordinates = new LatLng(50.4308233, 30.468171),
                    Id = Guid.NewGuid().ToString(),
                    Title = "test point",
                    SubTitle = "test point description",
                    IconImage = (ImageSource)"ic_pin8.png",
                    IsDraggable = false
                });
                Annotations.Add(new SymbolAnnotation
                {
                    Coordinates = new LatLng(50.4213206714367, 30.4711086026812),
                    Id = Guid.NewGuid().ToString(),
                    Title = "test point",
                    SubTitle = "test point description",
                    IconImage = (ImageSource)"ic_pin8.png",
                    IsDraggable = false
                });
                Annotations.Add(new SymbolAnnotation
                {
                    Coordinates = new LatLng(50.4392097647566, 30.4784340197486),
                    Id = Guid.NewGuid().ToString(),
                    Title = "test point",
                    SubTitle = "test point description",
                    IconImage = (ImageSource)"ic_pin8.png",
                    IsDraggable = false
                });
                Annotations.Add(new SymbolAnnotation
                {
                    Coordinates = new LatLng(50.4377507925521, 30.4584328331603),
                    Id = Guid.NewGuid().ToString(),
                    Title = "test point",
                    SubTitle = "test point description",
                    IconImage = (ImageSource)"ic_pin8.png",
                    IsDraggable = false
                });

            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.StackTrace);
                DisplayError(ex);
            }

        }


Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants