4

I'm trying to send a LinkedList from an Activity to an other one. In the first Activity I have:

LinkedList<Class> codaActivity;
/* Lots of code here... */
Intent intent = new Intent(this, codaActivity.remove());
intent.putExtra("codaRedditi", codaActivity); // this is putExtra(String, Serializable)
startActivity(intent);

In the second one, instead:

// The following throws a ClassCastException
codaRedditi=(LinkedList<Class>) (getIntent().getSerializableExtra("codaRedditi"));

When I try to run my app, the DVM throws a ClassCastException caused by that code (and talking about an ArrayList, that absolutely does't exists in the code! O.O)

What can be the mistake?

4

3 回答 3

2

您确定您正在访问的意图是您创建的意图吗?尝试调试意图,例如输出:

getIntent().getSerializableExtra("codaRedditi").getClass()

或对象本身:

getIntent().getSerializableExtra("codaRedditi")

你收到什么?

另外,您确定您使用正确LinkedList的演员阵容吗?查看进口,它是否说明:java.util.LinkedList

于 2012-10-07T14:41:08.470 回答
0

从文档:

public Intent putExtra (String name, Serializable value)

Since: API Level 1
Add extended data to the intent. The name must include a package prefix, for example the app com.android.contacts would use names like "com.android.contacts.ShowAll".

Parameters
name    The name of the extra data, with package prefix.
value   The Serializable data value.

它说,“名称”字段”应该有像“com.blah.something”这样的包前缀。也许这是导致问题的原因。

于 2012-10-07T15:03:25.677 回答
0

你确定intent是实例LinkedList吗?

试:

codaRedditi=new LinkedList((List)(getIntent().getSerializableExtra("codaRedditi")));
于 2012-10-07T14:32:41.130 回答