Answer the question
In order to leave comments, you need to log in
Why is a public variable not visible in another class?
I have a MainActivity class and I made an inner class in it to use AsyncTask. I decided to scatter these classes into different packages. But after that, my variables were no longer visible in the class for AsyncTask, although they are global and public. Well, for example:
In the MainActivity class, I have a field in front of all methods
public boolean isNavigationDrawerItemEnabled = false;
@Override
protected void onPreExecute() {
super.onPreExecute();
if (!isNavigationDrawerItemEnabled) {
progressDialog = new ProgressDialog(MainActivity.this);
progressDialog.setTitle("Новые");
progressDialog.setMessage("Загрузка...");
progressDialog.setIndeterminate(false);
progressDialog.show();
}
}
Answer the question
In order to leave comments, you need to log in
There are no global variables, you need to access through a reference to an instance of the class, or to the class itself, if the variable is static. Example with class instance:
package p1
public class one {
public boolean MyVar;
}
package p2
import p1.one
public class main{
class_one = new one();
class_one.myVar=true;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question