I'm currently writing an application to manage some data.
I have various lists of data, that are basically wrapper objects for HashMaps, with a few extra functions implemented, and a variable to store the next ID. Essentially, these make up a kind of flat-file database.
I am then using object serialization to save these lists to a file (1 list per file), and loading them back in again when the application starts.
Various classes need access to the data, and the data needs to exist in memory for these classes to access and modify, and when necessary to be able to call the MyList.save() method, which saves the object to disk.
Because of this, I need the objects to have public scope throughout the application.
Initially (when I only had 1 class to modify them) I just declared them as objects within that class.
I have tried creating an object (called DataStore) that had the lists as public static objects, but only the class that initialises the object (by doing DataStore.aList = (MyList) load("aList.dat");)
Other classes won't compile when I then try to access these objects by doing something like DataStore.aList.add() as I get the following error:
frmCatTest.java [62:1] cannot resolve symbol symbol : variable manufacturers location: class frmCatTest DataStore.manufacturers.add(new Category(manufacturers.getNextID(),"Test"));
The data is loaded in my Main class, and not in frmCatTest.
How should I declare the variables so that I can access them from various classes in the application?
Ah, I just spotted a very simple mistake, I had put "new Category(manufacturers.getNextID(),"Test"));" instead of "new Category(DataStore.manufacturers.getNextID(),"Test"));"
If anyone has any further comments about ensuring that I can access the data throughout the application then please reply. :)