Android Parcelable问题

时间:2013-12-29 13:40:26

标签: android classnotfoundexception parcelable

我在编组对象时遇到了问题(也实现了Parcelable)。我得到ClassNotFound异常。这是代码:

    public SongManager(Parcel in) {
    try {
        track = in.readParcelable(ClassLoader.getSystemClassLoader());
        random = new Random();
        shuffle = in.readByte() == 0 ? false : true;
        isTuning = in.readByte() == 0 ? false : true;
        currentTrack = in.readInt();
        currentTrackname = in.readString();
        base = new MusicDatabase(
                MusicPlayerActivity.currentActivity.getBaseContext());
        databaseSize = base.databaseSize();
        path = Environment
                .getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC);
        fis = new FileInputStream(new File(path, currentTrackname));
    } catch (Exception e) {
        e.printStackTrace();
    }
}

@Override
public void writeToParcel(Parcel dest, int flags) {
    dest.writeParcelable(track, 0);
    dest.writeByte((byte) (shuffle?1:0));
    dest.writeByte((byte) (isTuning?1:0));
    dest.writeInt(currentTrack);
    dest.writeString(currentTrackname);
}

主要问题是类Song,实例是对象轨道。这就是我得到例外的地方。记录下面的猫:

12-29 14:29:41.508: E/Parcel(6658): Class not found when unmarshalling: a.b.c.e.d.musicplayer.Song
12-29 14:29:41.508: E/Parcel(6658): java.lang.ClassNotFoundException: a.b.c.e.d.musicplayer.Song
12-29 14:29:41.508: E/Parcel(6658):     at java.lang.Class.classForName(Native Method)
12-29 14:29:41.508: E/Parcel(6658):     at java.lang.Class.forName(Class.java:305)
12-29 14:29:41.508: E/Parcel(6658):     at android.os.Parcel.readParcelableCreator(Parcel.java:2133)
12-29 14:29:41.508: E/Parcel(6658):     at android.os.Parcel.readParcelable(Parcel.java:2097)
...

0 个答案:

没有答案