The Artima Developer Community
Sponsored Link

Java Answers Forum
Make Data Accessible Throughout Application

1 reply on 1 page. Most recent reply: Apr 21, 2004 6:23 AM by Elliot Bowes

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Elliot Bowes

Posts: 2
Nickname: elliotb
Registered: Apr, 2004

Make Data Accessible Throughout Application Posted: Apr 21, 2004 6:21 AM
Reply to this message Reply
Advertisement
Hi

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?


Elliot Bowes

Posts: 2
Nickname: elliotb
Registered: Apr, 2004

Re: Make Data Accessible Throughout Application Posted: Apr 21, 2004 6:23 AM
Reply to this message Reply
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. :)

Thanks

Flat View: This topic has 1 reply on 1 page
Topic: passing arrays to another class Previous Topic   Next Topic Topic: Java Sales Tax Grand Total

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use