Pratham Jindal
Pratham Jindal

Reputation: 99

Caused by: java.lang.IllegalStateException: at android.os.Parcel.createExceptionOrNull

I am getting following exception in production environment. It is related with parcelable classes. But it is not showing which class is problematic. Below is detailed log trace:

java.lang.RuntimeException: 
  at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$getRunnable$0$LoadedApk$ReceiverDispatcher$Args (LoadedApk.java:1726)
  at android.app.-$$Lambda$LoadedApk$ReceiverDispatcher$Args$_BumDX2UKsnxLVrE6UJsJZkotuA.run (Unknown Source:2)
  at android.os.Handler.handleCallback (Handler.java:938)
  at android.os.Handler.dispatchMessage (Handler.java:99)
  at android.os.Looper.loop (Looper.java:264)
  at android.app.ActivityThread.main (ActivityThread.java:8306)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:632)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1049)
Caused by: java.lang.IllegalStateException:     at android.os.Parcel.createExceptionOrNull(Parcel.java:2397)
  at android.os.Parcel.createException(Parcel.java:2373)
  at android.os.Parcel.readException(Parcel.java:2356)
  at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:190)
  at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:142)
  at android.content.ContentProviderProxy.call(ContentProviderNative.java:733)
  at android.content.ContentResolver.call(ContentResolver.java:2435)
  at android.provider.DocumentsContract.moveDocument(DocumentsContract.java:1514)
  at com.package.name.FullScreenFace$f.a(:1)
  at c.d.a.d.a$a.onReceive(Unknown Source:249)
  at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$getRunnable$0$LoadedApk$ReceiverDispatcher$Args(LoadedApk.java:1691)
  ... 8 more

This is my Code for Model class using Parcelable:

public class Model implements Parcelable {

String author,language,type,gifFile,binFile;
String downloads,binFileName,gifFileName;
String id;
Timestamp addedon;

protected Model(Parcel in) {
    author = in.readString();
    language = in.readString();
    type = in.readString();
    gifFile = in.readString();
    binFile = in.readString();
    downloads = in.readString();
    binFileName = in.readString();
    gifFileName = in.readString();
    id = in.readString();
    addedon = in.readParcelable(Timestamp.class.getClassLoader());
}

public static final Creator<Model> CREATOR = new Creator<Model>() {
    @Override
    public Model createFromParcel(Parcel in) {
        return new Model(in);
    }

    @Override
    public Model[] newArray(int size) {
        return new Model[size];
    }
};

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

public boolean equals(Object object) {
    if (object != null && object instanceof Model) {
        return ((Model)object).id.equals((Object)this.id);
    }
    return super.equals(object);
}

@Override
public void writeToParcel(Parcel parcel, int i) {
    parcel.writeString(author);
    parcel.writeString(language);
    parcel.writeString(type);
    parcel.writeString(gifFile);
    parcel.writeString(binFile);
    parcel.writeString(downloads);
    parcel.writeString(binFileName);
    parcel.writeString(gifFileName);
    parcel.writeString(id);
    parcel.writeParcelable(addedon, i);
}
}

This is my Code for Proguard-rules files:

-keepattributes Signature

-keep class * implements android.os.Parcelable {
   *;
}

Can anybody help in solving this error?

Upvotes: 3

Views: 9871

Answers (2)

Android's Timestamp class extends the Date class. And Date class doesn't implement the Parcelable interface. So you cannot read and write the addedon variable. I think that is the problem. You can use long type to store timestamps and then convert it to Timestamp class via setTime(long time) method.

https://developer.android.com/reference/java/sql/Timestamp

Upvotes: 0

John De la cruz
John De la cruz

Reputation: 96

From what I see the problem may be that some of the values are null. I recommend that before you add readString() and readParcelable to add a conditional to make sure that the values are not null.

Upvotes: -1

Related Questions