<?xml version="1.0" encoding="UTF-8"?>
<java version="1.4.2_01" class="java.beans.XMLDecoder">
<object class="java.util.LinkedList"/>
</java>
Seems the do the LinkedList ok, why won't it do my class???
<snip />
| (anyone got a good concise description of what a bean is?) and they look
<http://java.sun.com/products/javabeans/FAQ.html>
<http://www.jguru.com/faq/JavaBeans>
<davidp />

Signature
David Postill
> Hi, I'm doing a uni student doing an assignment where I'm trying to save
> objects in a more persistent place than memory, so i was having a look
> at xml files. I came across XMLEncode and XMLDecode in java.beans
> (anyone got a good concise description of what a bean is?) and they look
> perfect for saving object representations to a file,
Not perfect, but appropriate for modestly sized amounts of data.
> but I'm having
> trouble getting the buggers to work.
[quoted text clipped - 3 lines]
> java.lang.IllegalAccessException: Class java.beans.Statement can not
> access a member of class Cinema with modifiers ""
You have to define public get/set methods for all content
you want to save. Instance variables, public or private are
not looked at.
> Secondly the offending Cinema class (just barebones for the moment):
>
> public class Cinema implements Serializable
OK
> {
> public static int id;
>
> Cinema()
Good. You need the default constructor.
> {
> this.id = 0;
> }
Define
public int getId() { return id; }
public void setId(int id) { this.id = id; }
Note capitalization. Then you should be fine.
If your bean has collections of objects, define
get/set methods that use arrays. E.g., if you have
a collection of doubles,
public double[] getScores() { return --make array of scores -- }
public void setScores(double[] scores) { -- store scores -- }
This is trivial if your internal collection is an array.
If it's a Collection, use things like toArray() and
Arrays.asList() to go back and forth.
John C. Bollinger - 21 Oct 2003 22:30 GMT
>>public class Cinema implements Serializable
>
[quoted text clipped - 17 lines]
>
> Note capitalization. Then you should be fine.
Also, chances are that you do not want the id variable to be static.
Static members are associated with the class, and shared by all
instances. If the purpose is data persistence then you would normally
want each data object to have its own state instead of shared state.
John Bollinger
jobollin@indiana.edu
Thanks to everyone who took the time to comment. Problem solved.
Ben.