相关疑难解决方法(0)

"使用包含ClassLoader作为参数的Parcel.read方法时,解组<myclass>"时出现"BadParcelableException:ClassNotFoundException"

给定一个自定义类org.example.app.MyClass implements Parcelable,我想写List<MyClass>一个包.我做了编组

 List<MyClass> myclassList = ...
 parcel.writeList(myclassList);
Run Code Online (Sandbox Code Playgroud)

每当我试图解散课程时

 List<MyClass> myclassList = new ArrayList<MyClass>();
 parcel.readList(myclassList, null);
Run Code Online (Sandbox Code Playgroud)

有一个"BadParcelableException: ClassNotFoundException when unmarshalling org.example.app.MyClass"例外.

这有什么不对?为什么找不到课程?

android marshalling unmarshalling parcel

49
推荐指数
4
解决办法
3万
查看次数

解组时ClassNotFoundException并且真的不知道为什么

固定:在底部回答

我正在为一个项目编写一个Android应用程序,我试图使用parcelable对象.我有2个可分类的课程.第一个是只有2个参数的普通类.第二个是具有附加属性的类,以及具有来自第一个类的类型的列表以及它的附加对象.

每次我尝试将第二个类的对象传递给另一个Activity时,我得到android.os.BadParcelableException:当解组时ClassNotFoundException

并关闭应用程序.

我现在搜索了几个小时并尝试了多种解决方案,但没有任 当我只将第一个类的对象传递给另一个活动时,错误不会发生.

这是我的代码:

package de.softwareproject.v3.testclasses;

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

public class Cart implements Parcelable {

private String name;
private Integer priceInCents;

public Cart() {}

public Cart(Parcel in){
    readFromParcel(in);
}

public String getName() {
    return name;
}
public void setName(String name) {
    this.name = name;
}
public Integer getPriceInCents() {
    return priceInCents;
}
public void setPriceInCents(Integer priceInCents) {
    this.priceInCents = priceInCents;
}

public static final Parcelable.Creator<Cart> CREATOR = new Parcelable.Creator<Cart>() {

            @Override
            public Cart createFromParcel(Parcel source) { …
Run Code Online (Sandbox Code Playgroud)

android unmarshalling parcelable

18
推荐指数
1
解决办法
1万
查看次数

BadParcelableException - BroadcastReceiver意图崩溃

这个错误似乎偶尔会发生,这很奇怪.它通常很好,但偶尔会爬起来.这是我的代码,它位于BroadcastReceiver中:

public void onReceive(Context context, Intent intent) {
    MyCustomResponseMsg message = new MyCustomResponseMsg((MyMessage) intent.getParcelableExtra(MyMessage.EXTRA_MESSAGE_KEY));

    // do stuff with the message

    setResultCode(Activity.RESULT_OK);
}
Run Code Online (Sandbox Code Playgroud)

以下是例外情况:

01-16 10:05:03.834: ERROR/AndroidRuntime(13533): FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start receiver com.(path-to-broadcast-receiver).MyReqReceiver:   
android.os.BadParcelableException: ClassNotFoundException when unmarshalling:  com.(path-to-my-message).MyMessage
at android.app.ActivityThread.handleReceiver(ActivityThread.java:1805)
at android.app.ActivityThread.access$2400(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:981)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.os.BadParcelableException: ClassNotFoundException when unmarshalling:     com.(path-to-my-message).MyMessage
at android.os.Parcel.readParcelable(Parcel.java:1958)
at android.os.Parcel.readValue(Parcel.java:1846)
at android.os.Parcel.readMapInternal(Parcel.java:2083)
at android.os.Bundle.unparcel(Bundle.java:208)
at …
Run Code Online (Sandbox Code Playgroud)

android broadcastreceiver parcelable android-intent badparcelableexception

8
推荐指数
1
解决办法
2173
查看次数

android.os.BadParcelableException:解组时的ClassNotFoundException:exception

值正在传递并且执行正常但我看到这些被抛入logcat并且我想要消除这些,我检查了较旧的论坛但没有具体.我发布下面的代码,请让我知道为什么会出现这个问题发生

public class ExecutionInfo implements Parcelable
{

    private int offSet;

    private List<Integer> pollingIntervalArray = new ArrayList<Integer>();

    private List<String> commandLst= new ArrayList<String>();

    private int repeatCount;

    private int executorId;

    private int processType;


    public ExecutionInfo()
    {

    }

    public ExecutionInfo(Parcel source)
    {
        offSet = source.readInt();
        repeatCount = source.readInt();
        executorId = source.readInt();
        processType = source.readInt();
        source.readStringList(commandLst);
        source.readList(pollingIntervalArray, Integer.class.getClassLoader());
    }

    public int getOffSet()
    {
        return offSet;
    }

    public void setOffSet(int offSet)
    {
        this.offSet = offSet;
    }

    public List<Integer> getInterval()
    {
        return pollingIntervalArray;
    }

    public void setInterval(List<Integer> …
Run Code Online (Sandbox Code Playgroud)

android marshalling parcel

7
推荐指数
1
解决办法
2万
查看次数

BadParcelableException:解组时的ClassNotFoundException

我是Serializable和Parcelable的新手.我很难将此对象的实例从应用程序传递到远程服务:

public class Event implements Parcelable, Cloneable {

    /** Defines under what Bundle's key architecture events are stored */ 
    public static final String BUNDLE_KEY = "ZKEvent";

    /** Defines which messages are architecture's events */
    public static final int MSG_WHAT = 0xDEFECABE;

    /** Defines a key to store map under a Bundle to put into a Parcel (oh yeah!) */
    private static final String MAP_KEY = "MAP";

    /** Indicates this event ID. This ID should be the same in the event …
Run Code Online (Sandbox Code Playgroud)

service android exception badparcelableexception

7
推荐指数
1
解决办法
1万
查看次数