pamela rizk
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.Resou rces android.content.Context.ge tResources ()' 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
and in the activity below is the function ResetImageClick
can anyone has a solution for the below error that occured in xamarin :
Attempt to invoke virtual method 'android.content.res.Resou
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 );
};
}
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
{
}
}
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers 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.