无法解决“遇到Parcelable遇到IOException编写可序列化对象”

问题描述 投票:0回答:1

java.lang.RuntimeException:遇到Parcelable的IOException编写可序列化的对象(名称= com.luzian.recipeapp.Recipe)

我已经在寻找这个问题的答案,但是似乎都可以通过让两个类都从Serializable实现来解决(我正在这样做-没有成功。)>

我的两堂食谱和配料:

public class Recipe implements Serializable
{
    private String name;
    private String time;
    private String instructions;
    private ArrayList<Ingredient> ingredients;

    public Recipe(String name, String time, String instructions, ArrayList<Ingredient> ingredients)
    {
        this.name = name;
        this.time = time;
        this.instructions = instructions;
        this.ingredients = ingredients;
    }
}


public class Ingredient implements Serializable
{
    private String value;
    private String unit;
    private String name;

    public Ingredient(String value, String unit, String name)
    {
        this.value = value;
        this.unit = unit;
        this.name = name;
    }
}

开始新活动:

Intent intent = new Intent(context, RecipeDisplayActivity.class);
intent.putExtra("recipe", recipes.get(position));     // recipes.get(position) returns a Recipe object
context.startActivity(intent);

java.lang.RuntimeException:可打包遇到IOException,正在编写可序列化的对象(名称= com.luzian.recipeapp.Recipe)。我已经在寻找此问题的答案,但它们似乎都...

java android exception runtimeexception serializable
1个回答
0
投票

我将Serializable更改为Parcelable,并重写了必需的方法-现在可以使用!

© www.soinside.com 2019 - 2024. All rights reserved.