我在从静态方法调用非静态方法时面临很大的问题。如何从静态方法调用非静态方法android
这是我的代码
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
}
我能叫Second_function但无法获得面包和CallCustomBaseAdapter()方法时,发生崩溃。
我应该怎么做才能解决这个问题?
发表您的崩溃日志这里.... –
你应该使用RunOnUiThread – Eun
尝试通过上下文来作为参数在使用静态方法的非静态方法中。我的意思是将上下文传递给静态方法,然后将相同的上下文传递给非静态方法。 – Dharmendra