sto usando il seguente codice per scrivere oggetto serializzabile su memoria esterna.
mi gela errore java.io.NotSerializableException anche il mio oggetto è serializzabile nessuno mi guida che errore sto facendo?
public class MyClass implements Serializable
{
// other veriable stuff here...
public String title;
public String startTime;
public String endTime;
public boolean classEnabled;
public Context myContext;
public MyClass(Context context,String title, String startTime, boolean enable){
this.title = title;
this.startTime = startTime;
this.classEnabled = enable;
this.myContext = context;
}
public boolean saveObject(MyClass obj) {
final File suspend_f=new File(cacheDir, "test");
FileOutputStream fos = null;
ObjectOutputStream oos = null;
boolean keep = true;
try {
fos = new FileOutputStream(suspend_f);
oos = new ObjectOutputStream(fos);
oos.writeObject(obj); // exception throws here
}
catch (Exception e) {
keep = false;
}
finally {
try {
if (oos != null) oos.close();
if (fos != null) fos.close();
if (keep == false) suspend_f.delete();
}
catch (Exception e) { /* do nothing */ }
}
return keep;
}
}
e chiamando da classe di attività a salvarlo
MyClass m= new MyClass(this, "hello", "abc", true);
boolean result =m.saveObject(m);
qualsiasi aiuto sarebbe apprezzato.
allora qual è la soluzione? qualche idea? – UMAR
Risposta aggiornata in merito al tuo commento – JesusFreke
sì ho rimosso il contesto e ora funziona correttamente. Grazie. – UMAR