【问题标题】:Using intent to sent arraylist value in android使用意图在android中发送arraylist值
【发布时间】:2014-08-26 07:41:39
【问题描述】:

想要将 ArrayList 发送到另一个活动, 在运行时使用面向意图的错误

"parcel: unable to marshal value error".

我的代码:

            Intent i = new Intent(getBaseContext(),SecondActitivty.class);

            Bundle extra = new Bundle();
            extra.putSerializable("objects", hotellista);

            try {
                /*Bundle bundle = new Bundle();  
                bundle.putSerializable("searchresul8t", hotellista);*/
                i.putExtra("searchrtre", extra);
                //i.putExtras(bundle);
                //i.putExtra("searchresult", hotellista);       

                startActivity(i);
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

【问题讨论】:

  • 您的ArrayList 包含哪些对象? ?
  • 你的activity是否实现了Serializable
  • 我在 bean 类中使用实现可序列化。但现在我也遇到类似 java.lang.RuntimeException: Parcelable 遇到 IOException 写入可序列化对象的错误
  • 所以你的bean类应该实现Parceable而不是serializable。请先发布你的堆栈跟踪,以便我们查明问题

标签: android android-intent arraylist


【解决方案1】:

你的类必须实现Parcelable,这样你就可以将它从Activity传递给另一个

【讨论】:

    【解决方案2】:

    试试这个

               Intent i = new Intent(getBaseContext(),SecondActitivty.class);              
    
                try {
                    i.putParcelableArrayListExtra("YourArrayList", yourarraylist);
          // or you can try like
                      i.putStringArrayListExtra("YourArrayList", yourarraylist);
    
                    startActivity(i);
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
    

    【讨论】:

    • 它说 Parcelable 遇到 IOException
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-18
    • 1970-01-01
    • 1970-01-01
    • 2012-07-17
    • 1970-01-01
    相关资源
    最近更新 更多