Ledid | Bonjour,
J'ai un souci de Serialization. Je tente de serializer un objet JXTreeTable (API SwingLabs) qui hérite de JTable. Théoriquement, ça devrait marcher puisque ces 2 classes sont serializables.
Le problème, c'est que lors de l'appel à la fonction writeObject, il me met systématiquement une erreur m'indiquant que java.beans.EventHandler n'est pas Serializable.
Voici mon code :
Code :
- public class JXTreeTableForecast extends JXTreeTable implements Serializable {
- private Plan plan;
- private int nbDisplayedPeriods;
- private int firstPeriodColumnIndex;
- public void save(String fileName) {
- FileOutputStream fos = null;
- ObjectOutputStream out = null;
- try {
- fos = new FileOutputStream(fileName + ".ser" );
- out = new ObjectOutputStream(fos);
- out.writeObject(this);
- out.close();
- } catch (IOException ex) {
- ex.printStackTrace();
- }
- }
- public static JXTreeTableForecast open(String fileName) {
- FileInputStream fis = null;
- ObjectInputStream in = null;
- JXTreeTableForecast table = null;
- try {
- fis = new FileInputStream(fileName + ".ser" );
- in = new ObjectInputStream(fis);
- table=(JXTreeTableForecast) in.readObject();
- in.close();
- } catch (IOException ex) {
- return null;
- } catch (ClassNotFoundException ex) {
- return null;
- }
- return table;
- }
- public static void main(String[] args) {
- JXTreeTableForecast treeTable;
- Plan plan = JXTreeTableForecast.createPlan(false);
- ForecastTreeTableModel model = new ForecastTreeTableModel(plan);
- Constants.init();
- Configuration.init();
- treeTable = JXTreeTableForecast.open("sauvegarde" );
- if (treeTable == null) {
- treeTable = new JXTreeTableForecast(model, plan, 2);
- }
- //Test pour voir si ça marche... Et ça plante!
- treeTable.save("sauvegarde" );
- JFrame f = new JFrame();
- f.getContentPane().add(treeTable);
- f.setLocation(50, 75);
- f.setSize(new Dimension(500,300));
- f.setVisible(true);
- f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- f.add(new JScrollPane(treeTable));
- }
- public static Plan createPlan(boolean siteOnRow) {
- Plan plan = new Plan();
- plan.setSiteOnRow(siteOnRow);
- plan.createLine("patisserie", new Client("Auchan", "AU2132" ));
- plan.createLine("saucisson", new Client("Leclerc", "LE1234" ));
- plan.initColumnNamesAndClasses();
- Period period = plan.getPeriods().get(0);
- ForecastPointFdR pointFdR = plan.getChildren().get(1).getPoint(period)
- .getPointFdR();
- pointFdR.setValue(20);
- pointFdR = plan.getChildren().get(0).getPoint(period).getPointFdR();
- pointFdR.setValue(40);
- pointFdR.addComment("Ceci est un premier commentaire" );
- pointFdR.addComment("Ceci est un deuxième commentaire" );
- return plan;
- }
- public JXTreeTableForecast(ForecastTreeTableModel model, Plan plan,
- int nbPeriodsToDisplay) {
- super(model);
- nbDisplayedPeriods = nbPeriodsToDisplay;
- firstPeriodColumnIndex = (plan.isSiteOnRow()) ? 5 : 4;
- this.plan = plan;
- setTreeCellRenderer(new TreeTableCellRenderer());
- HighlighterPipeline highlighters = new HighlighterPipeline();
- highlighters.addHighlighter(new AlternateRowHighlighter());
- setHighlighters(highlighters);
- expandRow(0);
- expandRow(1);
- addMouseMotionListener(new TreeTableMouseMotionListener(this));
- addMouseListener(new TreeTableMouseListener(this));
- packAll();
- setColumnControlVisible(true);
- }
- public Plan getPlan() {
- return plan;
- }
- }
|
et voici l'erreur :
Code :
- java.io.NotSerializableException: java.beans.EventHandler
- at java.io.ObjectOutputStream.writeObject0(Unknown Source)
- at java.io.ObjectOutputStream.defaultWriteFields(Unknown Source)
- at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
- at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
- at java.io.ObjectOutputStream.writeObject0(Unknown Source)
- at java.io.ObjectOutputStream.writeObject(Unknown Source)
- at javax.swing.event.EventListenerList.writeObject(Unknown Source)
- at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
- at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
- at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
- at java.lang.reflect.Method.invoke(Unknown Source)
- at java.io.ObjectStreamClass.invokeWriteObject(Unknown Source)
- at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
- at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
- at java.io.ObjectOutputStream.writeObject0(Unknown Source)
- at java.io.ObjectOutputStream.defaultWriteFields(Unknown Source)
- at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
- at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
- at java.io.ObjectOutputStream.writeObject0(Unknown Source)
- at java.io.ObjectOutputStream.writeObject(Unknown Source)
- at javax.swing.ArrayTable.writeArrayTable(Unknown Source)
- at javax.swing.ActionMap.writeObject(Unknown Source)
- at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
- at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
- at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
- at java.lang.reflect.Method.invoke(Unknown Source)
- at java.io.ObjectStreamClass.invokeWriteObject(Unknown Source)
- at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
- at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
- at java.io.ObjectOutputStream.writeObject0(Unknown Source)
- at java.io.ObjectOutputStream.defaultWriteFields(Unknown Source)
- at java.io.ObjectOutputStream.defaultWriteObject(Unknown Source)
- at javax.swing.JComponent.writeObject(Unknown Source)
- at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
- at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
- at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
- at java.lang.reflect.Method.invoke(Unknown Source)
- at java.io.ObjectStreamClass.invokeWriteObject(Unknown Source)
- at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
- at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
- at java.io.ObjectOutputStream.writeObject0(Unknown Source)
- at java.io.ObjectOutputStream.writeObject(Unknown Source)
- at forecast.table.JXTreeTableForecast.save(JXTreeTableForecast.java:42)
- at forecast.table.JXTreeTableForecast.main(JXTreeTableForecast.java:77)
- Exception in thread "main" java.lang.NullPointerException
- at javax.swing.plaf.basic.BasicTableUI.getPreferredSize(Unknown Source)
- at javax.swing.JComponent.getPreferredSize(Unknown Source)
- at javax.swing.JTable.setWidthsFromPreferredWidths(Unknown Source)
- at javax.swing.JTable.doLayout(Unknown Source)
- at java.awt.Container.validateTree(Unknown Source)
- at java.awt.Container.validateTree(Unknown Source)
- at java.awt.Container.validateTree(Unknown Source)
- at java.awt.Container.validateTree(Unknown Source)
- at java.awt.Container.validateTree(Unknown Source)
- at java.awt.Container.validate(Unknown Source)
- at java.awt.Window.show(Unknown Source)
- at java.awt.Component.show(Unknown Source)
- at java.awt.Component.setVisible(Unknown Source)
- at forecast.table.JXTreeTableForecast.main(JXTreeTableForecast.java:83)
|
Message édité par Ledid le 17-05-2006 à 14:53:10
|