简体   繁体   中英

Getting a class not found exception / noclassdeffound error on some Android devices

I have a class that implements Parcelable, which is throwing me a NoClassDefFoundError with class not found exception on some devices. Currently I have only gotten this error on Samsung Android devices. On Nexus 5, Nexus 4 and Android emulators it works as it should but not on Samsung for some reason. I have only tested this on the Samsung Remote Test Lab as I do not have a Samsung device for debugging.

Also the class in question is nothing special. A simple class with only longs, string and int written/read from the parcel. I checked that the order is the same when reading and writing. Additionally, the class is not referenced from a library.

ERROR   06-23 09:14:13.578  892 1507        Parcel  Class not found when unmarshalling: path.class

ERROR   06-23 09:14:13.578  892 1507        Parcel  Caused by: java.lang.NoClassDefFoundError: path/class

ERROR   06-23 09:14:13.578  892 1507        Parcel  Caused by: java.lang.ClassNotFoundException: Didn't find class "path.class" on path: DexPathList[[directory "."],nativeLibraryDirectories=[/vendor/lib, /system/lib]]

Code for the parcelable part of the class.

public class Sprint implements Parcelable {

    private long mStartTime;
    private long mEndTime;
    private int mDaysInSprint;
    private String mSprintTitle;
    private int mId;

    private Sprint(Parcel source) {
        mStartTime = source.readLong();
        mEndTime = source.readLong();
        mDaysInSprint = source.readInt();
        mSprintTitle = source.readString();
        mId = source.readInt();
    }
    public static final Parcelable.Creator<Sprint> CREATOR = new Parcelable.Creator<Sprint>() {
        @Override
        public Sprint createFromParcel(Parcel source) {
            return new Sprint(source);
        }
        @Override
        public Sprint[] newArray(int size) {
            return new Sprint[size];
        }
    };

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

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeLong(mStartTime);
        dest.writeLong(mEndTime);
        dest.writeInt(mDaysInSprint);
        dest.writeString(mSprintTitle);
        dest.writeInt(mId);
    }

This error may cause because of API version compatibility. Please check and use latest version of API. Am not sure but as per my knowledge this is the reason

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM