Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parcelable encountered IOException writing serializable object

Tags:

android

So basically i went through this tutorial http://mindtherobot.com/blog/37/android-architecture-tutorial-developing-an-app-with-a-background-service-using-ipc/

Because it is more or less what i want to achieve. I want my GPS service to be running in the background constantly collecting GPS coordinates and saving them to an array, that way a user can swap to another activity and come back to the Map activity and have it still plot the most their entire recorded path.

So i implemented this tutorial to set up the IPC and it seems to be working more or less but i am having a problem getting the data back to my Activity. Here are my files, first is my Parcelable object that is a list that will hold GPSObject's. Next are my GPSObject's which are just a serializable object that contains some of the information from a android Location object.

package com.android.SnowFever;

import java.util.ArrayList;
import java.util.List;

import com.android.SnowFever.*;
import com.google.android.maps.GeoPoint;

import android.os.Parcel;
import android.os.Parcelable;

public final class GPSResult implements Parcelable {

public static final Creator<GPSResult> CREATOR = new Creator<GPSResult>() {
    @Override
    public GPSResult[] newArray(int size) {
        return new GPSResult[size];
    }

    @Override
    public GPSResult createFromParcel(Parcel source) {
        return new GPSResult(source);
    }
};

private List<GPSObject> geoPoints;

public GPSResult() {
    geoPoints = new ArrayList<GPSObject>();
}

@SuppressWarnings("unchecked")
private GPSResult(Parcel source) {
    geoPoints = source.readArrayList(GPSService.class.getClassLoader());
}

public void addGPS(GPSObject location) {
    geoPoints.add(location);
}

public List<GPSObject> getGeoPoints() {
    return geoPoints;
}

@Override
public int describeContents() {
    return 0;
}

@Override
public void writeToParcel(Parcel dest, int flags) {
    dest.writeList(geoPoints);
}

}

And this is my GPSObject class

package com.android.SnowFever;

import java.io.Serializable;

import com.google.android.maps.GeoPoint;

import android.location.Location;

public class GPSObject implements Serializable{

/**
 * 
 */
private static final long serialVersionUID = 1L;

float spd, acc;
double lat, lng, alt;
GeoPoint gp;

public GPSObject(Location l) {
    lat = l.getLatitude() * 1E6;
    lng = l.getLongitude() * 1E6;
    alt = l.getAltitude();
    spd = l.getSpeed();
    acc = l.getAccuracy();
    gp = new GeoPoint((int)lat,(int)lng);
}

}

To add files to my GPSResult list i call

latestGPSResult.getGeoPoints().add(new GPSObject(location));

And i get the error included in the thread topic, a larger chunk of the error window below

11-01 18:49:06.818: E/JavaBinder(20754): *** Uncaught remote exception!  (Exceptions are not yet supported across processes.)
11-01 18:49:06.818: E/JavaBinder(20754): java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = com.android.SnowFever.GPSObject)
11-01 18:49:06.818: E/JavaBinder(20754):    at android.os.Parcel.writeSerializable(Parcel.java:1176)
11-01 18:49:06.818: E/JavaBinder(20754):    at android.os.Parcel.writeValue(Parcel.java:1130)
11-01 18:49:06.818: E/JavaBinder(20754):    at android.os.Parcel.writeList(Parcel.java:519)
11-01 18:49:06.818: E/JavaBinder(20754):    at com.android.SnowFever.GPSResult.writeToParcel(GPSResult.java:52)
11-01 18:49:06.818: E/JavaBinder(20754):    at com.android.SnowFever.GPSApi$Stub.onTransact(GPSApi.java:52)
11-01 18:49:06.818: E/JavaBinder(20754):    at android.os.Binder.execTransact(Binder.java:320)
11-01 18:49:06.818: E/JavaBinder(20754):    at android.os.BinderProxy.transact(Native Method)
11-01 18:49:06.818: E/JavaBinder(20754):    at com.android.SnowFever.GPSListener$Stub$Proxy.handleGPSUpdated(GPSListener.java:76)
11-01 18:49:06.818: E/JavaBinder(20754):    at com.android.SnowFever.GPSService$GeoUpdateHandler.onLocationChanged(GPSService.java:91)
like image 533
user1024792 Avatar asked Nov 02 '11 02:11

user1024792


2 Answers

This means that the com.android.SnowFever.GPSObject object is not serializable. I suppose a GeoPoint is not serializable. This mean you must implement writeObject and readObject.

like image 179
rds Avatar answered Oct 27 '22 01:10

rds


I think your problem is that the GeoPoint is not a Serializable object. I had the same problem and it was because I had an Uri in my Class which was implementing Serializable interface.

like image 26
Ciprian Avatar answered Oct 27 '22 00:10

Ciprian