Link to home
Start Free TrialLog in
Avatar of pamela rizk
pamela rizkFlag for Lebanon

asked on

xamarin mobile application access to resource error

dear all

can anyone has a solution for the below error that occured in xamarin :
Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference
here is a brief description for my case:
i have an activity and an adapter where this adapter 3 images and 2 labels
upon clicking on the image i am doing the below in adapter
if (!imageView4.HasOnClickListeners)
            {
                //Clicking on upload button
                imageView4.Click += async delegate
                 {
                   
                     var m_HolderID = "";
                     m_HolderID = m_ReferenceNum.ToString().Trim();
                   
                         Activity1 m_Activity1 = new Activity1 ();
                         await  m_Activity1.ResetImageClick(p_Activity, m_HolderID );
                        
                 };
            }

Open in new window


and in the activity below is the function ResetImageClick
public void ResetImageClick(Activity p_Activity, int m_StkTakeNum)
        {
            string m_Message = p_Activity.GetString(Resource.String.StkTakeReset);
            ShowToastMsg(p_Activity,m_Message);
        }
 public void ShowToastMsg(Activity p_Activity,string message, bool IsLengthShort = false)
        {
            try
            {
                Handler mainHandler = new Handler(Looper.MainLooper);
                Java.Lang.Runnable runnableToast = new Java.Lang.Runnable(() =>
                {
                    var duration = IsLengthShort ? ToastLength.Short : ToastLength.Long;
                    //    RunOnUiThread(() =>
                    //    {
                    Toast.MakeText(p_Activity, message, duration).Show();////SHOW MSG CANNOT BE USED INSIDE ASYN METHOD
                    //    });
                    //}
            });
                mainHandler.Post(runnableToast);
            }
            catch
            {

            }

        }

Open in new window

This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.