I have an application which interacts with a custom service via two aidl implementations. When the service is ran, I am running into the following exception:
ERROR/AndroidRuntime(9435): FATAL EXCEPTION: main
ERROR/AndroidRuntime(9435): java.lang.NullPointerException
ERROR/AndroidRuntime(9435): at android.os.Parcel.readException(Parcel.java:1328)
ERROR/AndroidRuntime(9435): at android.os.Parcel.readException(Parcel.java:1276)
ERROR/AndroidRuntime(9435): at myservice.IAsyncService$Stub$Proxy.addItems(IAsyncService.java:259)
From this error, I think it is something to do with the marshalling which is carried out. So I checked both aidl implementations; the first aidl (which uses primitives) seemed to work fine (I think because they dont need me to specify imports/implementations); the second (which uses a custom object) however seems to crash giving the above error. I have made sure the custom object correctly implements parcelable (see bottom of post for implementation), and have even tried referencing the custom object from a separate aidl file as shown below.
(Seperate aidl file.) - (IMyItem.aidl)
package myservice;
parcelable myservice.MyItem;
(Other aidl file.) - (IAsyncService.aidl)
package myservice;
import myservice.IMyItem;
interface IAsyncService
{
void addItems(in List<MyItem> itemCollection);
}
(Parcelable Implementation) (MyItem)
public class MyItem implements Parcelable
{
private String name = "";
public MyItem(String name)
{
this.name = name.trim();
}
public MyItem(Parcel source) {
readFromParcel(source);
}
public void setItem(String name)
{
this.name = name;
}
public String getName()
{
return this.name;
}
public static final Parcelable.Creator<MyItem> CREATOR = new Parcelable.Creator<MyItem>() {
@Override
public MyItem[] newArray(int size) {
return new MyItem[size];
}
@Override
public MyItem createFromParcel(Parcel source) {
return new MyItem(source);
}
};
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel destination, int flags) {
destination.writeString(this.name);
}
public void readFromParcel(Parcel source) {
this.name = source.readString();
}
}
Is there something I am missing or have completely overlooked?
Thanks John