• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Creating an XML save file

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to save data in a JList to an XML file. But it doesn't seem to even create the xml file. I need help. I am very new to this Java stuff....Below is my code.

 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Don't know. How are you debugging that code? What error messages do you get? Does new File actually create a file?

I shall move this discussion as too difficult for “beginning”.
 
Daniel Kochheiser
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't get any errors. And new file is not creating a file at all. I am using Eclipse Luna with Window Builder to write this code and teach myself.

I have had no formal training in Java, so I am really lost as to why it doesn't seem to work and doesn't generate any errors that I can tell.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, let's take it from the beginning then. First: how do you know that code is even being executed?
 
Daniel Kochheiser
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I will answer in my best noob ways...

The program piles and runs when I click the Save menu item, the program flickers a little then nothing happens. When I click any button or menu item besides Save and Load, the action occurs. And the Exit Menu Item executes flawlessly with the same action listener code as the Save, basically. So I assume that the code is running, but I am unsure on how to find out.
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you have a debugger in the environment where you're compiling and running the code? If so, then definitely spend some time learning how to use it. Otherwise, inserting a lot of System.out.println statements is the poor man's debugger.

That's assuming that when you run your code you can actually see the output of such statements; often when you run "java abc" from the command line you can't. Which may be part of your problem -- if you can't see them then you have no way to tell whether the code threw an exception, because you can't see the output from e.printStackTrace (which goes to System.err). So it would be a good idea to find out whether that's the case or not.
 
Daniel Kochheiser
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So how do I find if there is a debugger in the environment. Where would I look?

 
Daniel Kochheiser
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Found it. output means nothing to me. Here is the output.

com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 11 counts of IllegalAnnotationExceptions
javax.swing.ListCellRenderer is an interface, and JAXB can't handle interfaces.
this problem is related to the following location:
at javax.swing.ListCellRenderer
at public javax.swing.ListCellRenderer javax.swing.JList.getCellRenderer()
at javax.swing.JList
at private javax.swing.JList com.cooksys.assessment.TestGui.list1
at com.cooksys.assessment.TestGui
javax.swing.ListModel is an interface, and JAXB can't handle interfaces.
this problem is related to the following location:
at javax.swing.ListModel
at public javax.swing.ListModel javax.swing.JList.getModel()
at javax.swing.JList
at private javax.swing.JList com.cooksys.assessment.TestGui.list1
at com.cooksys.assessment.TestGui
javax.swing.ListSelectionModel is an interface, and JAXB can't handle interfaces.
this problem is related to the following location:
at javax.swing.ListSelectionModel
at public javax.swing.ListSelectionModel javax.swing.JList.getSelectionModel()
at javax.swing.JList
at private javax.swing.JList com.cooksys.assessment.TestGui.list1
at com.cooksys.assessment.TestGui
javax.swing.border.Border is an interface, and JAXB can't handle interfaces.
this problem is related to the following location:
at javax.swing.border.Border
at public javax.swing.border.Border javax.swing.JComponent.getBorder()
at javax.swing.JComponent
at javax.swing.JList
at private javax.swing.JList com.cooksys.assessment.TestGui.list1
at com.cooksys.assessment.TestGui
java.awt.datatransfer.FlavorMap is an interface, and JAXB can't handle interfaces.
this problem is related to the following location:
at java.awt.datatransfer.FlavorMap
at public java.awt.datatransfer.FlavorMap java.awt.dnd.DropTarget.getFlavorMap()
at java.awt.dnd.DropTarget
at public synchronized java.awt.dnd.DropTarget java.awt.Component.getDropTarget()
at java.awt.Component
at public java.awt.Component javax.swing.JPopupMenu.getInvoker()
at javax.swing.JPopupMenu
at public javax.swing.JPopupMenu javax.swing.JComponent.getComponentPopupMenu()
at javax.swing.JComponent
at javax.swing.JList
at private javax.swing.JList com.cooksys.assessment.TestGui.list1
at com.cooksys.assessment.TestGui
javax.swing.SingleSelectionModel is an interface, and JAXB can't handle interfaces.
this problem is related to the following location:
at javax.swing.SingleSelectionModel
at public javax.swing.SingleSelectionModel javax.swing.JPopupMenu.getSelectionModel()
at javax.swing.JPopupMenu
at public javax.swing.JPopupMenu javax.swing.JComponent.getComponentPopupMenu()
at javax.swing.JComponent
at javax.swing.JList
at private javax.swing.JList com.cooksys.assessment.TestGui.list1
at com.cooksys.assessment.TestGui
java.awt.LayoutManager is an interface, and JAXB can't handle interfaces.
this problem is related to the following location:
at java.awt.LayoutManager
at public java.awt.LayoutManager java.awt.Container.getLayout()
at java.awt.Container
at javax.swing.JComponent
at javax.swing.JList
at private javax.swing.JList com.cooksys.assessment.TestGui.list1
at com.cooksys.assessment.TestGui
javax.swing.Action is an interface, and JAXB can't handle interfaces.
this problem is related to the following location:
at javax.swing.Action
at public javax.swing.Action javax.swing.AbstractButton.getAction()
at javax.swing.AbstractButton
at javax.swing.JMenuItem
at javax.swing.JMenu
at public javax.swing.JMenu javax.swing.JMenuBar.getHelpMenu()
at javax.swing.JMenuBar
at public javax.swing.JMenuBar javax.swing.JFrame.getJMenuBar()
at javax.swing.JFrame
at com.cooksys.assessment.TestGui
javax.swing.Icon is an interface, and JAXB can't handle interfaces.
this problem is related to the following location:
at javax.swing.Icon
at public javax.swing.Icon javax.swing.AbstractButton.getDisabledIcon()
at javax.swing.AbstractButton
at javax.swing.JMenuItem
at javax.swing.JMenu
at public javax.swing.JMenu javax.swing.JMenuBar.getHelpMenu()
at javax.swing.JMenuBar
at public javax.swing.JMenuBar javax.swing.JFrame.getJMenuBar()
at javax.swing.JFrame
at com.cooksys.assessment.TestGui
javax.swing.ButtonModel is an interface, and JAXB can't handle interfaces.
this problem is related to the following location:
at javax.swing.ButtonModel
at public javax.swing.ButtonModel javax.swing.AbstractButton.getModel()
at javax.swing.AbstractButton
at javax.swing.JMenuItem
at javax.swing.JMenu
at public javax.swing.JMenu javax.swing.JMenuBar.getHelpMenu()
at javax.swing.JMenuBar
at public javax.swing.JMenuBar javax.swing.JFrame.getJMenuBar()
at javax.swing.JFrame
at com.cooksys.assessment.TestGui
java.awt.Shape is an interface, and JAXB can't handle interfaces.
this problem is related to the following location:
at java.awt.Shape
at public java.awt.Shape java.awt.Window.getShape()
at java.awt.Window
at java.awt.Frame
at javax.swing.JFrame
at com.cooksys.assessment.TestGui

at com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException$Builder.check(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.<init>(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.<init>(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(Unknown Source)
at com.sun.xml.internal.bind.v2.ContextFactory.createContext(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 javax.xml.bind.ContextFinder.newInstance(Unknown Source)
at javax.xml.bind.ContextFinder.newInstance(Unknown Source)
at javax.xml.bind.ContextFinder.find(Unknown Source)
at javax.xml.bind.JAXBContext.newInstance(Unknown Source)
at javax.xml.bind.JAXBContext.newInstance(Unknown Source)
at com.cooksys.assessment.TestGui$4.actionPerformed(TestGui.java:120)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.AbstractButton.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$400(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

This outputs to the console when I press the save option in my file menu. clicking anything else does not generate anything in the console. Did not test load as I know there is no file to load right now.
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So why are you trying to marshal a ListCellRenderer? I don't see the point of that -- a ListCellRenderer doesn't usually contain any useful data.
 
Daniel Kochheiser
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So I don't know what a listcellrenderer is.

What I am doing is transferring a Jlist into another Jlist and then trying to save that second Jlist as an XML file.

The first Jlist is a listmodel prefilled with elements.

The second jlist is a listmedel that a jbutton adds the slected element in the first jlist to the second jlist.

The first jlist is called list. the second jlist is called list1.
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah, I see. You haven't fully understood the difference between the model and the view in a Swing application. The "view" is the GUI components you see on the screen, such as JLists and JButtons. The "model" is the data behind those components. If you want to serialize something in your Swing application, you should make sure you're serializing data from the model, because serializing GUI components is almost totally pointless. In the case of a JList you'll find the data in its model, which you can find by calling its getModel() method.

I don't know if JAXB can deal with an AbstractListModel, either, because you don't want to serialize the model's listeners. Usually this is handled by declaring fields transient, which the standard Java serialization methods pay attention to, but I don't know whether JAXB does. But give it a try anyway and see what happens.
 
Daniel Kochheiser
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So you understand the problem, I gather. I am teaching myself Java. So most of what you said, make sense in a general way, but what it is that I am to do about it is not explained enough for me to know what I should be doing.

So how do I get the data in the listmodel to be turned into data that can be put into a XML file? I don't know how one would make something transient.

If you can tell me something that is better for my purposes than the AbstractListModel let me know. Right now, the AbstractListModel is allowing me to select things from Jlist list in any order I want and copy it to Jlist list1 and also delete the data from Jlist list1 in any order I so choose.

Examples of coding you are talking would be highly appreciated, if if all you do is point me to the resoucres that can show how to do this would be great.

I appreciate the time you have taken to help me with this so far.
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So did you try serializing your list model with JAXB?

Personally when I wanted to serialize data from Java into XML I always used XMLEncoder. Was there a particular reason you chose JAXB or was it just the first object-to-XML technology you happened to find?
 
Daniel Kochheiser
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since I don't know how to serialize anything in Java, no I didn't.

JAXB was just the first thing I found.
 
Daniel Kochheiser
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I really do need help with this concept. Like I said earlier I am very new to this Java programming and I am teaching myself. I need to know how to do this. Please help me.

Even though you have moved this to Java in general, I really am just a beginner and need assistance.
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since you're a beginner, could I suggest that you don't try to learn about everything all at once?

So let me ask you... why do you need to use XML to serialize your data? Once you make that choice then you have the question of which XML-serialization tool to use, and how to use it (usually a learning curve appears here). Why not just use the ordinary serialization via ObjectOutputStream and ObjectInputStream?
 
Daniel Kochheiser
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need to save data as an xml file and then load data from an xml file. It is part of an end goal project. I am trying to learn everything I need to fit the parameters of a project on a small scale before I try it on a larger scale. So I am teaching myself by doing something very basic that is only marginally related to the end goal project.
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay. Then I'd suggest something more straightforward than JAXB -- check out XMLEncoder and XMLDecoder. I assume you already have a link to the API documentation? If not then you should, because it's pretty hard to do Java programming as a beginner without it. You'll find those classes in there.

And I would suggest you find a tutorial about XMLEncoder and go through it. Put aside your current project and learn how to use those classes, then when you are up to speed on them, apply your knowledge to your current project. In general that's what you should do every time you find yourself having to learn a new technology.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic