我試圖存儲一些對象以備將來在網絡故障時處理。 我有一個NameValuePairs在一個Serializeable類的數組...我已經消除了一切,但我得到一個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;
}
}
什麼是進入NameValuePair?也許一個不可序列化的值? – 2011-05-06 00:31:59
嘗試創建一個獨立的程序來完成此操作。它看起來像problrm是你在NameValuePair中放入的東西。包含在你的對象中的所有東西都需要可序列化。 – 2011-05-06 00:32:58
不,他們都是這樣或那樣的字符串...有沒有我應該尋找的非法價值? – 2011-05-06 00:33:46