Misguided planning.


    Jan 21 2007 | 5:30 pm
    Help!
    I've painted myself into a bit of a corner. Havning finally really wrapped my head around the handiness and functionality of references, I designed a data structure which is quite elegant... or at least clear and functional for my purposes.
    To make this as simple as possible -- I've got two classes A and B. When I load a midi file, the data from the midi file is organized into a number of A objects and a number of B objects. A objects basically contain vertical data (harmony), while B objects contain horizontal data (motives). The A objects hold references to B objects, and vice versa.
    I'm trying to save all this data in a file. In order to access the data, I've loaded all of the A objects from an analyzed midi file into a HashMap: Map. However, when I save Map, it appears that the actual data from the B objects gets left behind -- if I query the B data from a loaded Map file, I get NullPointerExceptions, suggesting that there's no B data stored. Because the A objects are actually loaded to the Map and saved, all of the A object data appears to be intact.
    So, how can I save the Map in such a way as to also save the referenced B data?
    Does that question make any sense? Is this Java 101?
    J.

    • Jan 21 2007 | 5:56 pm
      Sounds like you may have to make B implement the serializable interface or come up with your own mechanism to serialize your objects to disk. topher
      On Jan 21, 2007, at 17:30 PM, jbmaxwell wrote:
      > > Help! > > I've painted myself into a bit of a corner. Havning finally really > wrapped my head around the handiness and functionality of > references, I designed a data structure which is quite elegant... > or at least clear and functional for my purposes. > > To make this as simple as possible -- I've got two classes A and B. > When I load a midi file, the data from the midi file is organized > into a number of A objects and a number of B objects. A objects > basically contain vertical data (harmony), while B objects contain > horizontal data (motives). The A objects hold references to B > objects, and vice versa. > > I'm trying to save all this data in a file. In order to access the > data, I've loaded all of the A objects from an analyzed midi file > into a HashMap: Map. However, when I save Map, it appears that the > actual data from the B objects gets left behind -- if I query the B > data from a loaded Map file, I get NullPointerExceptions, > suggesting that there's no B data stored. Because the A objects are > actually loaded to the Map and saved, all of the A object data > appears to be intact. > > So, how can I save the Map in such a way as to also save the > referenced B data? > > Does that question make any sense? Is this Java 101? > > J. > >
    • Jan 21 2007 | 6:06 pm
      Quote: topher lafata wrote on Sun, 21 January 2007 17:56 ---------------------------------------------------- > Sounds like you may have to make B implement the serializable > interface or come up with your own > mechanism to serialize your objects to disk. > topher >
      Yeah, you know, guided by exception.toString() messages, I figured out the Serializable stuff, but it still doesn't seem to be working. In the meantime I read up on this general problem, and the Serializable interface does seem to be the answer. So, I made my A and B classes both serializable, but I'm still getting empty B objects in my Map.
      Since A seems okay, I'm taking a closer look at B. Thanks, Topher.
      J.