I am facing a big problem in calling non static method from static method.
This is my code
Class SMS
{
public static void First_function()
{
SMS sms = new SMS();
sms.Second_function();
}
public void Second_function()
{
Toast.makeText(getApplicationContext(),"Hello",1).show(); // This i anable to display and cause crash
CallingCustomBaseAdapters(); //this was the adapter class and i anable to call this also
}
I am able to call Second_function but unable to get Toast and CallCustomBaseAdapter() method, crash occurs.
What should I do to fix that issue ?
The only solution to achieve this is that you need to pass the current context as a parameter. I wrote the code for only Toast but you need to modify it as per your requirements.
pass the Context from the your activity
First_function(getApplicationContext())
etc..for static string
You should have a reference to a Context. You are trying to get the application context from inside a SMS instance.
I guess you are calling the First_function from an Activity or Service. So you can do this:
Then, from your activity: