How to call non static method in android ?? I have try all way I can, but nothing. i have try this code in java and success for running, but why in android always error.
Here is the code of main activity.
public class Main extends Activity{
private Coba mstatus;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void onClick(View v)
{
switch (v.getId()){
case R.id.download:
....
break;
case R.id.resume:
mstatus.resume();
break;
}
}
This is the second class.
public abstract class Coba implements runnable{
....
public void resume(){
download();
}
public void download() {
mThread = new Thread(this);
mThread.start();
}
}
I want to call resume() method. In my source code nothing warning and error but when I try to call this method it’s always force close. Is there another way to call non static method from another class ??
It’s rather a java issue than an Android one:
First Coba is abstract so you should use a non abstract class, let’s call this class CobaImpl
or make Coba a non abstract class (you choose).
Second you should create an instance of the class to use a non static method (eg mstatus = new CobaImpl(…) elsewhere you can use only static method.