I'm doing a little class to save and load information from a game, by the moment I have coded this:
import java.io.FileReader;
import java.io.FileWriter;
import org.exolab.castor.xml.MarshalException;
import org.exolab.castor.xml.Marshaller;
import org.exolab.castor.xml.Unmarshaller;
import org.exolab.castor.xml.ValidationException;
class InformationToStoreLoad{
public InformationToStoreLoad(){
}
}
public class GameSaverLoader {
/*
* Save the current game
*/
public void saveXML(){
FileWriter writer;
try {
writer = new FileWriter("save.xml");
Marshaller.marshal(new InformationToStoreLoad(), writer);
writer.close();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
/*
* Load a game saved before
*/
public void loadXML()
{
try {
FileReader reader = new FileReader("article.xml");
InformationToStoreLoad gameToLoad =
(InformationToStoreLoad) Unmarshaller.unmarshal(InformationToStoreLoad.class, reader);
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
I have been working on .NET platforms and I'm a little bit noob with Java, so I'm not sure if I have done everything right. To export the Castor libraries I have right clicked on my project, I have selected Properties, then Java Build Path, then libraries, and finally I have clicked "Add external JAR" and I have exported this JAR: "castor-1.3.1-xml.jar"
However, I have the following error while using the marshaller and unmarshaller classes
Unhandled exception type ValidationException
If I select "Add catch clause to surrounding try" on quick fixes, then I get this errors instead:
No exception of type MarshalException can be thrown; an exception type must be a subclass of Throwable
The method printStackTrace() is undefined for the type MarshalException
No exception of type ValidationException can be thrown; an exception type must be a subclass of Throwable
The method printStackTrace() is undefined for the type ValidationException
Also in the quick fixes I have the option to make this:
public void saveXML() throws MarshalException, ValidationException{
then I get this error:
No exception of type MarshalException can be thrown; an exception type must be a subclass of Throwable
No exception of type ValidationException can be thrown; an exception type must be a subclass of Throwable
I don't know how to fix any of those errors, anyone can advise me how to solve this problems?
Best regards