I\'m having some issues with the old \"Cannot make a static reference to a non-static method\" error in my Android program. I am creating a sand falling game (similar to the
You have to call showDialog
on a DemoActivity
instance, NOT on the class itself. The only time you can call ClassName.methodName()
is if the method is defined as static. showDialog
is not a static method.
To fix this, you either need to instantiate a new DemoActivity
or get an existing one, then call showDialog
on that.
Edit: If you already have a DemoActivity
instance when you instantiate this Control
object, perhaps the following modification will work:
public class Control extends LinearLayout
{
...
// add an Activity instance
private Activity activity;
// set the Activity in your constructor
public Control(Context context, AttributeSet attrs, Activity activity)
{
super(context, attrs);
this.activity = activity;
}
@Override
protected void onFinishInflate()
{
...
// Use the instance activity here
activity.showDialog(2);
...
}
}
if the create is called by ANDROID, so you do not create the instance, just put into the create mShowDialog=this
or mShowDialog=pShowDialog
in other words - have the create save the instance value also you can add a public get to get that instance value. Then you can access the instance function through the abstract by interceding the getter:
ABSTRACTCLASS.getInstance().applyFunction();