我正在尝试存储一些对象,以便在发生网络故障时进行后续处理。
我在Serializeable类中有一个NameValuePairs数组...我已经消除了其他所有内容,但仍然出现NotSerializeableException ...我从没尝试过将Serializeable对象写入文件...确定我在做一些愚蠢的事情,但看不到它是什么...
public void store(){
FileOutputStream fos = null;
ObjectOutputStream out = null;
try {
Log.d(TAG, "Upload failed, saving file to " + path + "/" + fileName);
File f = new File(path);
if(!f.exists()){
try{
(new File(path)).mkdirs();
}catch(Exception e){
Log.d(TAG, "failed to create directory " + path );
}
}
f = new File(path + "/" + fileName);
fos = new FileOutputStream(f);
out = new ObjectOutputStream(fos);
Parts p = new Parts(parts);
out.writeObject(p); //THIS IS THE LINE WHERE IT DIES WITH THAT EXCEPTION
out.flush();
out.close();
} catch (IOException e) {
Log.d(TAG, "FAILED TO SAVE file: " + path + "/" + fileName );
Log.d(TAG, "error:" + e);
} catch(Exception e){
Log.d(TAG, "error:" + e);
}
}
private class Parts implements Serializable{
private static final long serialVersionUID = -7603433209073871781L;
@SuppressWarnings("unused")
public NameValuePair [] p;
public Parts(NameValuePair [] parts){
this.p = parts;
}
}
最佳答案
如果对象实现Serializable
并且其所有非瞬态和非静态字段都是可序列化的,则该对象是可序列化的。您的NameValuePair
是否可序列化?
后续:观察docs,NameValuePair
实现Serializable
。 String[]
也是可序列化的。您看到的异常是什么?