This is interesting, but I wrote this code:
void Save()
{
switch(mode) {
case 1:
for (int i = 0; i<cir.size(); i++)
{
save.saves(cir.get(i));
}
break;
case 2:
if (pendul)
{
for (int i = 0; i< pend.size(); i++)
{
save.saves(pend.get(i));
}
} else
{
for (int i = 0; i< doublePend.size(); i++)
{
save.saves(doublePend.get(i));
}
}
break;
}
}
class SaveGame
{
Gson gson;
String json;
JSONObject js;
SaveGame()
{
gson = new Gson();
}
void saves(Object obj)
{
json = gson.toJson(obj);
js = parseJSONObject(json);
boolean exist;
if (js != null)
{
File f;
int i = -1;
do
{
i++;
f = dataFile("saves/save" + i + ".txt");
exist = f.isFile();
}
while (exist);
println(i, " ",f , " ",exist);//, " ",js, " ",json);
saveJSONObject(js, "saves/save" + i + ".txt");
}
}
}
But this isn’t working, and I have this errors: SEVERE: An error occured while forwarding a Controller event, please check your code at Save java.lang.reflect.InvocationTargetException Caused by: java.lang.IllegalArgumentException: class java.awt.Frame declares multiple JSON fields named state
That I don’t know how to resolve. Can you help me with that?