【问题标题】:IO Exception writing serializable object? passing images arraylist写入可序列化对象的 IO 异常?传递图像数组列表
【发布时间】:2019-01-22 02:34:14
【问题描述】:

类Selected_img_layout:

 Intent i = new Intent(Selected_img_layout.this, ImagSlider.class);
                Bundle bundle = new Bundle();
                bundle.putSerializable("image_data", spacecrafts);
                i.putExtras(bundle);
                startActivity(i);

类 ImagSlider:

 Bundle bundleobject = getIntent().getExtras();
 spacecrafts = (ArrayList<Spacecraft>) bundleobject.getSerializable("image_data");

类航天器:

public class Spacecraft implements Serializable {
        Uri uri;

        public Spacecraft() {
        }

        public Spacecraft(String name, Uri uri) {
            this.name = name;
            this.uri = uri;
        }

        public Uri getUri() {
            return uri;
        }

        public void setUri(Uri uri) {
            this.uri = uri;
        }
     }

错误

 java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = com.example.letsgo.mypdfconverter.Spacecraft)

【问题讨论】:

  • 请发布完整的Spacecraft 课程。您发布的内容可能无法编译。

标签: object runtime-error parcelable serializable


【解决方案1】:

替换这个:

 public Spacecraft(String name, Uri uri) {
            this.name = name;
            this.uri = uri;
        }

与:

 public Spacecraft( Uri uri) {
            this.uri = uri;
        }

【讨论】:

    【解决方案2】:

    试试这个代码: 意图 i = new Intent(Selected_img_layout.this, ImagSlider.class); i.putExtras("image_data",航天器); startActivity(i);

    试试这个以在另一个活动中获取您的数据

    航天器 spaceCraft =(Spacecraft)getIntent().getSerializableExtra("image_data")

    【讨论】:

    • 不能在 putextras 中传递一个数组列表(画廊选择的图像)
    • spacecrafts 是 Spacecraft 的对象,它扩展了 Serializable 接口,因此您可以通过它,因为它是可序列化的格式
    猜你喜欢
    • 2012-10-29
    • 2013-10-13
    • 2021-03-08
    • 1970-01-01
    • 2023-03-30
    • 2017-12-09
    • 2013-05-10
    • 2018-08-20
    • 2015-05-10
    相关资源
    最近更新 更多