我想创建一个保存对象的系统。我正在使用处理。现在我这样做:
void Save()
{
Gson gson = new Gson();
String json = "0";
JSONObject js;
JSONArray values = new JSONArray();
switch(mode) {
case 1:
for (int i = 0; i<cir.size(); i++)
{
json = gson.toJson(cir.get(i));
js = parseJSONObject(json);
values.setJSONObject(i, js);
}
break;
case 2:
if (pendul)
{
for (int i = 0; i< pend.size(); i++)
{
json = gson.toJson(pend.get(i));
js = parseJSONObject(json);
values.setJSONObject(i, js);
}
} else
{
for (int i = 0; i< doublePend.size(); i++)
{
json = gson.toJson(doublePend.get(i));
js = parseJSONObject(json);
values.setJSONObject(i, js);
}
}
break;
}
save.saves(values);
}
class SaveGame
{
Gson gson;
String json;
JSONObject js;
SaveGame()
{
gson = new Gson();
}
void saves(JSONArray obj)
{
boolean exist = true;
if (obj != null)
{
File f;
int i = -1;
do
{
i++;
f = dataFile("saves/save" + i + ".txt");
exist = f.isFile();
}
while (exist);
println(f, " ",obj);
saveJSONArray(obj, "saves/save" + i + ".txt");
}
}
}
但有些东西不起作用,我有很多错误,我不知道为什么:
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
有人能帮我吗?整个项目在这里:https://github.com/rafhub69/everythig
暂无答案!
目前还没有任何答案,快来回答吧!