0

First post by a newbi - please be gentle :) I'm currently writing a database of vehicles in a museum. I am able to save it as XML. However I recently tried adding images of the vehicles into the database via a dialogStage which worked well until I tried to save as XML. Now I get the error that it can't save and all I have is an empty XML file. I am using FileChooser to upload the image. The TextArea fileLocation is used to display the location that the image has been uploaded from. The only way I can see around this is to scrap using .toURI and instead upload the images to a designated folder automatically without having to use a save dialog so that the XML doesn't have to try saving the images which is what I believe is breaking it). I have spent days browsing here and other sites and trying various methods but to no avail. I include the FileChooser method below. Can anyone help me at all please? Any alternative solutions are equally welcome. Many Thanks in advance.

@FXML
private TextArea fileLocation;

private Image image;
private File file;
private FileChooser fileChooser;

{
    final FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle("Select Image");
    file = fileChooser.showOpenDialog(dialogStage);
    if(file != null)
    {
        fileLocation.setText(file.getAbsolutePath());
        image = new Image(file.toURI().toString(), 140, 212, true, true);
        imageView.setImage(image);
        imageView.setFitWidth(140);
        imageView.setFitWidth(212);
        imageView.setPreserveRatio(true);

    }
}
Maverick
  • 1
  • 1
  • What is the error? What, specifically, are you trying to save as XML (the image? the path to the file? the URI?). Can you post the complete [stack trace](https://stackoverflow.com/q/3988788/2775450) in the question, and identify the line in the code that is throwing the exception? – James_D May 01 '18 at 12:41
  • The database lists cars and bikes which are saved as an XML file and can loaded into a tableview as required. There is no error in the stack trace. The error is thrown up by a pop up alert that I have 'Could not save data to file: C;\...'. What I believe is happening is that the XML file does not save images. So I would like the images sent to a specific folder that the database can call on. The uploaded image location is set as a string in a hidden column in the tableview, the name and location of which is controlled by the line: 'image = new Image(file.toURI().toString()' – Maverick May 01 '18 at 15:50

0 Answers0