I'm attempting to write a literal string to a file that can then be loaded. Here is my current code:
Now, when I run this code, it basically crashes Greenfoot, and I have no idea why. It says "Actor cannot be written to java.lang.String". What am I doing wrong, and how can I possibly fix it?
int x = 0;
int y = 0;
String actorStringRaw;
String actorStringFinal;
String stringToWrite;
List actorList;
public void writeFile()
{
FileWriter fw = null;
for (int i=0; i<(getWidth()); i++)
{
if (getObjectsAt(x, y, null) != null)
{
try
{
fw = new FileWriter("Save.txt");
List<String> actorList = (getObjects(null));
for (int j=0; j<actorList.size(); j++)
{
actorStringRaw = actorList.get(j);
String[] actorStringArray = actorStringRaw.split("@");
actorStringFinal = actorStringArray[0];
stringToWrite = ("addObject(" + actorStringFinal + ", " + x + ", " + y + ");");
fw.write(stringToWrite + " ");
}
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
if(fw != null)
{
try {
fw.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
x += 1;
}
else
{
x += 1;
}
if (x > getWidth())
{
x = 0;
y += 1;
}
}
}

