0

I'm trying to make a toast message in Xamarin.Forms with the Plugin.Toast Nuget-Package.

Class for calling Toast:

using Plugin.Toast;
using System;
using System.Collections.Generic;
using System.Text;
using Xamarin.Essentials;

namespace toast.service
{
    public class toast
    {

        public void toastWarning(string msg)
        {
          CrossToastPopUp.Current.ShowToastWarning(msg, Plugin.Toast.Abstractions.ToastLength.Short);
        }

    
    }
}

Calling toast code:

service.toast toast = new service.toast();
toast.toastWarning("test");

But I alwas get this error: System.NullReferenceException: 'Object reference not set to an instance of an object.'

  • Does this answer your question? [What is a NullReferenceException, and how do I fix it?](https://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – madreflection May 16 '22 at 15:44
  • 2
    If you want help specific to your code, at least figure out *what* is `null`, first. If, after doing that, you can't figure out *why* it's `null`, then post a question. – madreflection May 16 '22 at 15:46
  • that plugin has not been updated in 2 years – Jason May 16 '22 at 15:46
  • 1
    if you can provide more details like the error stack – Mina Fawzy May 16 '22 at 16:38

1 Answers1

1

There is no need to use a Plugin. Xamarin provide Android.Widget.Toast library to show message.

   Toast.MakeText(this, "Received intent!", ToastLength.Short).Show();

enter image description here

Wendy Zang - MSFT
  • 10,509
  • 1
  • 7
  • 17