In my application
the class central is instantiate as like below :
central.java :
mContext = getApplicationContext();
mMyStuff = new MyStuff(mContext);
MyStuff class need to get the mContext to access from some resources.
MyStuff.java :
public class MyStuff {
private Context mContext;
public MyStuff(Context c) {
mContext = c;
}
....
private ActionCustom MyAction = new ActionCustom(mContext);
issue is that mContext is always null even in c is not null. I was expecting that when doing the new MyStuff(mContext)
issue is that mContext is always null even in c is not null
Because currently :
private ActionCustom MyAction = new ActionCustom(mContext);
line executed before calling MyStuff
class constructor where initialization of mContext
object is done .
Do it as:
private ActionCustom MyAction;
public MyStuff(Context c) {
mContext = c;
MyAction = new ActionCustom(mContext);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With