小编use*_*494的帖子

如何为android.location类序列化?

我正在尝试序列化我的位置类(使用android.location类)

但是,它给了我一个错误!

11-21 21:25:37.337: W/System.err(3152): java.io.NotSerializableException: android.location
Run Code Online (Sandbox Code Playgroud)

所以,我试图扩展android.location.Location课程.

private class NewLocation extends Location implements Serializable {
        private String Provider;
        private double Latitude, Longitude, Altitude;

private float bear;
        public NewLocation(Location l) {
            super(l);
            Provider = l.getProvider();
            Latitude = l.getLatitude();
            Longitude = l.getLongitude();
            Altitude = l.getAltitude();
            bear = l.getBearing();
        }
    }
Run Code Online (Sandbox Code Playgroud)

之后,我试图序列化扩展类,但同样的错误.

这是序列化代码

 public static byte[] serialize(Object obj) throws IOException {
        ByteArrayOutputStream bao = new ByteArrayOutputStream();
        ObjectOutput oos = new ObjectOutputStream(bao);
        byte[] data = null;
        oos.writeObject(obj);
        oos.flush();
        oos.close();
        data = …
Run Code Online (Sandbox Code Playgroud)

java serialization android location deserialization

5
推荐指数
1
解决办法
4668
查看次数

标签 统计

android ×1

deserialization ×1

java ×1

location ×1

serialization ×1