I'm trying to use GSON in my Swing User Interface, when I'm trying to create a GSON object I get an error considering java.applet.Applet
class. The weird thing is that I'm not even using Applet
elements to save or load using GSON.
Can someone explain to me what is happening?
The code is below.
The error I'm getting
java.lang.IllegalArgumentException: class java.applet.Applet declares multiple JSON fields named accessibleContext
Loading Object to json on button click:
JButton selectProfileSaveLocationButton = new JButton("Select Location");
selectProfileSaveLocationButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//todo create new empty profile
JFileChooser jfc = new JFileChooser(FileSystemView.getFileSystemView().getHomeDirectory());
jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int returnValue = jfc.showSaveDialog(null);
if (returnValue == JFileChooser.APPROVE_OPTION) {
if (jfc.getSelectedFile().isDirectory()) {
profileSaveLocationTextfield.setText(jfc.getSelectedFile().getAbsolutePath());
try {
System.out.println("Saving file to: " + jfc.getSelectedFile().getAbsolutePath() + File.separatorChar + profileNameTextfield.getText() + ".json");
File dataFile = new File(jfc.getSelectedFile().getAbsolutePath() + File.separatorChar + profileNameTextfield.getText() + ".json");
//dataFile.createNewFile();
Data.botProfileLocation = dataFile;
SlayerProfile profile = newEmptyProfile(profileNameTextfield.getText());
String json = FryslanSlayer.gson.toJson(profile);
System.out.println(json);
FileWriter writer = new FileWriter(Data.botProfileLocation.getAbsolutePath());
FryslanSlayer.gson.toJson(profile, writer);
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
}
});
selectProfileSaveLocationButton.setBackground(new Color(65, 105, 225));
selectProfileSaveLocationButton.setForeground(new Color(0, 0, 139));
selectProfileSaveLocationButton.setBounds(610, 274, 124, 25);
generalPanel.add(selectProfileSaveLocationButton);