AndroidRuntime错误:包裹:不能编组值 [英] AndroidRuntime error: Parcel: unable to marshal value
问题描述
我想一个HashMap传递给使用intent.puExtra功能的新的活动。通过调试器步进似乎它增加了HashMap中没有问题,但是当startActivty()被调用我得到一个运行时错误,指出包裹:不能编组值com.appName.Liquor
I am trying to pass a HashMap to a new activity using the intent.puExtra function. Stepping through the debugger it seems that it adds the HashMap no problem, however when startActivty() is called I get a runtime error stating that Parcel: unable to marshal value com.appName.Liquor.
酒是我创建了一个自定义类,而我相信,在一个HashMap的组合,是造成问题。如果我通过一个字符串,而不是我的HashMap,它加载下一个活动没有任何问题。
Liquor is a custom class that I created, and I believe it, in combination with a HashMap, is causing the problem. If I pass a string rather than my HashMap it loads the next activity no problem.
主要活动
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
String cat = ((TextView) view).getText().toString();
Intent i = new Intent(OhioLiquor.this, Category.class);
i.putExtra("com.appName.cat", _liquorBase.GetMap());
startActivity(i);
白酒类
public class Liquor
{
public String name;
public int code;
public String category;
private HashMap<String, Bottle> _bottles;
public Liquor()
{
_bottles = new HashMap<String, Bottle>();
}
public void AddBottle(Bottle aBottle)
{
_bottles.put(aBottle.size, aBottle);
}
}
子活动
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
HashMap<Integer, Liquor> map = (HashMap<Integer, Liquor>)getIntent().getSerializableExtra("com.appName.cat");
setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, GetNames(map)));
ListView lv = getListView();
lv.setTextFilterEnabled(true);
在运行时错误存在,它永远不会使它进入子活动类。所以我pretty的肯定,在HashMap中的增加的意图,并根据关我相信我的白酒类是错误原因存在的问题,但我想不出为什么。
When the runtime error exists it never makes it into the sub activity class. So I'm pretty sure the problem exists in the adding of the HashMap to the intent, and based off the error I believe my Liquor class is the cause, but I can't figure out why.
您的帮助将非常AP preciated。谢谢!
Your help will be much appreciated. Thanks!
推荐答案
您的HashMap
本身是可序列化的,但是是瓶
类序列化?如果不是这样,就不会序列化和将在运行时引发错误。
使瓶
类实现的java.io.Serializable
接口
Your HashMap
itself is serializable but is the Bottle
class serializable? If not, it will not serialize and will throw errors at runtime.
Make the Bottle
class implement the java.io.Serializable
interface
这篇关于AndroidRuntime错误:包裹:不能编组值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!