我使用下面的代碼來序列化一個對象,並通過putSerializable將它附加到一個包,然後通過消息發送包到其他進程。問題是我得到一個對象不可序列化的錯誤。我試圖添加「實現Serialazable」,但我仍然得到相同的錯誤。發送一個包到其他進程
public static byte[] serializeObject(Object o)
{
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
ObjectOutput out = new ObjectOutputStream(bos);
out.writeObject(o);
out.close();
// Get the bytes of the serialized object
byte[] buf = bos.toByteArray();
return buf;
} catch(IOException ioe) {
Log.e("serializeObject", "error", ioe);
return null;
}
}
這是代碼,撥打電話:
ArrayList<byte[]> blist=null;
Bundle b = new Bundle();
if (TriggerList != null && TriggerList.size() > 0)
{
Iterator iter = TriggerList.iterator();
while (iter.hasNext())
{
Bundle entry = (Bundle) iter.next();
if (msg.arg1 == entry.getInt(ProjDefs.APP_ID))
{
if (blist == null)
blist=new ArrayList<byte[]>();
SerBundle sb = new SerBundle(entry);
byte[] bb = serializeObject(sb);
blist.add(bb);
}
}
b.putSerializable(ProjDefs.SERIAL_DATA, blist);
}
NotifyClient(msg.arg1, ProjDefs.GET_APP_TRIGGERS_RESPONSE, 0, 0, b, null);
的序列化類:
公共類SerBundle實現Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
public Bundle bundle;
public SerBundle(Bundle bundle)
{
this.bundle = bundle;
}
}
@Simon:u能與其中u正準備捆綁,並實現Serialazable – 2012-04-24 10:36:23
代碼編輯您的帖子補充說打的電話 – Simon 2012-04-24 10:50:27
是U確保您 – 2012-04-24 10:53:58