1
listObject
のコピーを作成するにはどうすればよいですか? listObjectのカスタマイズオブジェクトのコピーを作成するには? Java
クラス:ここ
static class listObject {
ArrayList<String> diseases;
ArrayList<String> images;
static class guide {
ArrayList<String> guideTitle;
ArrayList<String> guideText;
ArrayList<String> guideImage;
}
}
は私コピー機能である:
public static Object copy(Object orig) {
Object obj = null;
try {
// Write the object out to a byte array
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(bos);
out.writeObject(orig);
out.flush();
out.close();
// Make an input stream from the byte array and read
// a copy of the object back in.
ObjectInputStream in = new ObjectInputStream(
new ByteArrayInputStream(bos.toByteArray()));
obj = in.readObject();
}
catch(IOException e) {
e.printStackTrace();
}
catch(ClassNotFoundException cnfe) {
cnfe.printStackTrace();
}
return obj;
}
私はコピー()関数を呼び出すと、それはリターンヌルです:
listObject list;
listObject _tempList = new listObject();
list = (listObject) copy((Object) _tempList);
'obj'がnull以外の値に設定することができる唯一の場所はin.readObject''であるので、そのメソッドがnullを返しているように見えます。 –
listObjectクラスは 'serializable'または' externalizable'インターフェイスを実装していますか?これらのクラスだけをストリームから読み込むことができます。 –
上記の 'salud'は何ですか? – nullpointer