unmarshallin时找不到类

时间:2015-01-04 23:56:22

标签: java android android-intent parcelable

我的android项目中有这个DTO类:

package com.example.stopcall.app.dal.dto;


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

public class Phone implements Parcelable {
    public int id;
    public String phone;
    public boolean isBlocked;

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

    @Override
    public void writeToParcel(Parcel out, int flags) {
        out.writeInt(id);
        out.writeString(phone);
        out.writeInt(isBlocked ? 1 : 0);
    }


    public static final Parcelable.Creator<Phone> CREATOR
            = new Parcelable.Creator<Phone>() {
        public Phone createFromParcel(Parcel in) {
            return new Phone(in);
        }

        public Phone[] newArray(int size) {
            return new Phone[size];
        }
    };

    private Phone(Parcel in) {
        id = in.readInt();
        phone = in.readString();
        isBlocked = in.readInt() == 1 ? true : false;
    }

    public Phone() {
    }
}

然而,当我运行SendDialIntent();时:

@Override
public void onDialogPositiveClick() {
    persistNumberIsAllowed();
    SendDialIntent();
    finish();
}

private void SendDialIntent() {
    Intent intent = new Intent(Intent.ACTION_DIAL);
    intent.setData(Uri.parse("tel" + phone.phone));
    startActivity(intent);
}

我收到此运行时错误:

01-05 01:50:13.271    2459-2881/? E/Parcel﹕ Class not found when unmarshalling: com.example.stopcall.app.dal.dto.Phone
    java.lang.ClassNotFoundException: com.example.stopcall.app.dal.dto.Phone
            at java.lang.Class.classForName(Native Method)
            at java.lang.Class.forName(Class.java:251)
            at java.lang.Class.forName(Class.java:216)
            at android.os.Parcel.readParcelableCreator(Parcel.java:2133)
            at android.os.Parcel.readParcelable(Parcel.java:2097)
            at android.os.Parcel.readValue(Parcel.java:2013)
            at android.os.Parcel.readArrayMapInternal(Parcel.java:2314)
            at android.os.Bundle.unparcel(Bundle.java:249)
            at android.os.Bundle.getString(Bundle.java:1118)
            at android.content.Intent.getStringExtra(Intent.java:5145)
            at com.android.server.am.ActivityStackSupervisor.startActivityLocked(ActivityStackSupervisor.java:1467)
            at com.android.server.am.ActivityStackSupervisor.startActivityMayWait(ActivityStackSupervisor.java:1063)
            at com.android.server.am.ActivityManagerService.startActivityAsUser(ActivityManagerService.java:4066)
            at com.android.server.am.ActivityManagerService.startActivity(ActivityManagerService.java:3964)
            at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:159)
            at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2645)
            at android.os.Binder.execTransact(Binder.java:404)
            at dalvik.system.NativeStart.run(Native Method)

我错过了什么?

2 个答案:

答案 0 :(得分:1)

这看起来像这个错误:

https://code.google.com/p/android/issues/detail?id=6822

这个问题可能重复:

https://stackoverflow.com/questions/23461869/unmarshalling-error-class-definition-not-found-when-setting-an-alarm-using-an-in?rq=1

然而,问题在于解组包裹,应该首先将对象放在一个包中来修复它,如下所示:

Bundle bundle = new Bundle();
bundle.putParcelable("com.example.stopcall.app.dal.dto.Phone", phone);

答案 1 :(得分:0)

我只缺少:

   intent.setData(Uri.parse("tel" + phone.phone));

为:

intent.setData(Uri.parse("tel:" + phone.phone));