Reputation: 319
I have an object called Run, that contains 4 strings, a string[], 2 float[], and 3 floats. It implements serializable so I could write it to a File. Here's the code I use to save the file...
}else{
run.setName(runName.getText().toString());
FileOutputStream fos = this.openFileOutput(runName.getText().toString(), Context.MODE_PRIVATE);
ObjectOutputStream os = new ObjectOutputStream(fos);
os.writeObject(run);
os.close();
fos.close();
Toast.makeText(this,"Run saved!", Toast.LENGTH_LONG).show();
Intent intent = new Intent(this, MainScreen.class);
startActivity(intent);
finish();
}
This works fine with no errors, but when I try to retrieve it in another activity I get the NotSerializableException. Here's the code I use to retrieve it...
FileInputStream fileInput = this.openFileInput(name);
ObjectInputStream objectInput = new ObjectInputStream(fileInput);
Run run = (Run) objectInput.readObject();
fileInput.close();
objectInput.close();
It causes an error on the Run run = (Run) objectInput.readObject();, and on the else in the above code. How could I solve this issue?
Upvotes: 0
Views: 174
Reputation: 311054
The class named in the exception doesn't implement Serializable.
Change the class named in the exception so it does implement Serializable.
Repeat until closure. If it's a JRE class or another class not under your control you'll have to review why you're trying to serialize it in the first place .
Upvotes: 1