A question about static data members
So I have this class call DocReader and sets some information it recieves to a data member. Except DocReader is used by a bunch of other classes to. So one classes uses DocReader to get the name of the user, but when I try to use a different class to the same data member(which is a string), it declares it as null.
Could this all be solved is the data member was made static so different classed can access the same data member in that one class DocReader?
[470 byte] By [
blackmagea] at [2007-11-27 4:54:10]

If your two different classes that use DocReader have the same reference to DocReader, then they access the same data. But if you're instantiating DocReader twice -- once in each of the two classes that use it -- then they will be accessing different objects and thus different information.
So in summary you don't need to make it static (although this will work), you just need both classes that use it to have the same reference.
How are boths classes using it as the same references.
Like I have
public class UserWindow{
DocReader doc=new DocReader();
doc.setUser("Fred");
}
and then
public class SearchForUser{
DocReader doc=new DocReader();
doc.getUser("Fred");
}
for the second one, should is just have
public class SearchForUser{
DocReader doc;
doc.getUser("Fred");
}
bc when I do that, I get a NullPointerException e