序列化ArrayList <arraylist <mypoint>&gt;不工作

时间:2016-11-11 16:11:38

标签: java android serialization arraylist

有一个ArrayList&gt;,如何序列化?

ArrayList<ArrayList<MyPoint>> polygons;

        try {
            FileOutputStream fileOut = openFileOutput("polygons.ser", MODE_PRIVATE);
            ObjectOutputStream out = new ObjectOutputStream(fileOut);
            out.writeObject(pv.polygons);
            out.close();
            fileOut.close();
            Log.d("Polygons Output", pv.polygons.toString());
            Log.d("Polygons Output Out", out.toString());
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }


        try {
            FileInputStream fileIn = openFileInput("polygons.ser");
            ObjectInputStream in = new ObjectInputStream(fileIn);
            ArrayList<ArrayList<MyPoint>> arr = new ArrayList<>();
            pv.polygons = (ArrayList<ArrayList<MyPoint>>) in.readObject();
            in.close();
            fileIn.close();
        } catch (IOException io) {
            io.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

Log.d显示[[Point(0,0),....]]的数组列表。

outputStream位于onSaveInstance中,inputStream位于onCreate()中。 MyPoint扩展了Point实现Serializable ......

为什么不起作用?

0 个答案:

没有答案