【问题标题】:How to fix InvocationTargetException when sending hashmap to other activity将哈希图发送到其他活动时如何修复 InvocationTargetException
【发布时间】:2020-02-02 21:10:51
【问题描述】:

我正在尝试发送 HashMap 以使用 startActivity(intent). 开始新活动

我遵循了这个链接的答案: How to send hashmap value to another activity using an intent

但我仍然得到错误

当然,我尝试发送字符串

intent.putExtra("test","some String");
startActivity(intent);

成功了

我的代码:

HashMap<String,Diner> dinersOrdersHasMap = new HashMap<String,Diner>();
FillHashMap(); // Fill the HashMap with data

Intent intent = new Intent(this, BillForm.class);
intent.putExtra("dinersOrderHashMap",dinersOrdersHasMap);
startActivity(intent);

例外:

   "Could not execute method for android:onClick", e);

    e.detailMessage = "Parcelable encountered IOException writing serializable 
    object (name = com.example.myfirstapp.Diner)

当我打电话时 startActivity(intent);

【问题讨论】:

    标签: java android hashmap


    【解决方案1】:

    你的 Diner 类是 Serializable 还是 Parcelable ?

    您可以在这里发布您的 Diner 课程吗?

    【讨论】:

    • 你说得对!我改了class Diner implements Serializable
    猜你喜欢
    • 2011-11-26
    • 2019-05-21
    • 1970-01-01
    • 2021-06-16
    • 1970-01-01
    • 2023-03-03
    • 2016-04-08
    • 2012-02-02
    • 1970-01-01
    相关资源
    最近更新 更多