Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/181.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 活动从可包裹对象接收空值_Android_Android Intent_Null_Parcelable_Serializable - Fatal编程技术网

Android 活动从可包裹对象接收空值

Android 活动从可包裹对象接收空值,android,android-intent,null,parcelable,serializable,Android,Android Intent,Null,Parcelable,Serializable,我使用一个可包裹的物体通过一个意图。我的物体看起来像这样 enter code here @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_recipe); dbMan = new XmlManager(); try { db = db

我使用一个可包裹的物体通过一个意图。我的物体看起来像这样

enter code here @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_recipe);

    dbMan = new XmlManager();
    try {
        db = dbMan.parse();
    } catch (XmlPullParserException e) {
        System.err.println("XmlPullParserException " + e.getMessage());
        e.printStackTrace();
    } catch (IOException e) {
        System.err.println("IO Excepion " + e.getMessage());
        e.printStackTrace();
    }

    // get the listview
    expListView = (ExpandableListView) findViewById(R.id.expandableListView1);

    // preparing list data
    prepareListData();

    listAdapter = new MyBaseExpandableListAdapter(this, listDataHeader,
            listDataChild);

    // setting list adapter
    expListView.setAdapter(listAdapter);
    // Listview on child click listener
    expListView.setOnChildClickListener(new OnChildClickListener() {

        @Override
        public boolean onChildClick(ExpandableListView parent, View v,
                int groupPosition, int childPosition, long id) {
            sendChildList = listDataChild 
                    .get(listDataHeader.get(groupPosition))
                    .get(childPosition).toString();
            sendRecipe = dbMan.getRecipyByCriteria(db, sendChildList);

            Toast.makeText(getApplicationContext(),
                    "sendet" + sendChildList, Toast.LENGTH_LONG).show();
            Intent in = new Intent(getApplicationContext(),
                    ShowRecipe.class);
            in.putExtra("sendRecipe", sendRecipe);

            startActivity(in);
            return false;
        }
    });
}
在此处输入代码
公共类配方实现可包裹{ 私有列表配方=null; 私有列表成分=null; 私人字符串准备

public Recipe(List<String> recipe, List<String> ingredients,
        String preparation) {
    this.recipe = recipe;
    this.ingredients = ingredients;
    this.preparation = preparation;
}

public Recipe(Parcel source) {

    source.readStringList(recipe);
    source.readStringList(ingredients);
    this.preparation = source.readString();
}

public List<String> getRecipe() {
    return recipe;
}

public List<String> getIngredients() {
    return ingredients;
}

public String getPreparation() {
    return preparation;
}

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

@Override
public void writeToParcel(Parcel dest, int flags) {
    dest.writeStringList(recipe);
    dest.writeStringList(ingredients);
    dest.writeString(preparation);

}

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

    @Override
    public Recipe[] newArray(int size) {
        return new Recipe[size];
    }

    @Override
    public Recipe createFromParcel(Parcel source) {
        return new Recipe(source);
    }
};}
我调试了这部分代码,我知道sendRecipe对象是实例化的,数据是正确的

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_show_recipe);
    findeRecipe = (Recipe)getIntent().getParcelableExtra("sendRecipe");

在这个地方,Intent接收空值。这很有趣,因为当我发送字符串或int时,它的接收是正确的。我坐在这里进行调试,这件事阅读关于Parcelable的问题,做所有正确的事情,但没有任何正确的事。

可能问题在于你使用了应用程序上下文:
Intent in=new Intent(getApplicationContext()…
尝试传递活动。

可能您面临大小限制?请看:它不可能是我发送的2个列表,其中包含4或5个字符串和一个字符串。您尝试传递活动的意思是什么。要初始化意图,您必须为其提供一个参数getApplicationContext()或getBaseContext().我指的是主要活动.比如说这个