Issue
I’m using AsyncTask to load bitmaps in the background. I created a class Mybackground that inherits from AsyncTask. If I do the following it works,
new MyBackground().execute();
But when I call it this way,
MyBackground mBackground=new MyBackground();
mBackground.p1=1;
mBackground.p2="tets";
MyBackground.execute();
I get the error cannot make a static reference to a non static. Why am I getting this error. Is there a way to do this? If not what would be a good way to pass in 2 different arguments, since execute only takes in 1 parameter?
Solution
You would call mBackground.execute()
which calls the execute
method of a particular instance of your MyBackground
class.
Calling new MyBackground().execute()
creates a new MyBackground
instance and then calls execute on that, which is why you don't get the error.
Take a look at Java: static and instance methods if you are unsure on what the difference between a static and instance method is.
Static methods do not require an instance of that type to exist, and static properties are shared between all instances of a class.
Answered By - Joseph Earl
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.