简体   繁体   中英

Xamarin Plugin.Toast System.NullReferenceException

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.'

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();

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM