IO Exception编写可序列化对象?传递图像arraylist

问题描述 投票:0回答:2

class 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);

class 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)
object runtime-error parcelable serializable
2个回答
0
投票

替换这个:

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

有:

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

0
投票

试试这个代码:Intent i = new Intent(Selected_img_layout.this,ImagSlider.class); i.putExtras( “IMAGE_DATA”,宇宙飞船); startActivity(ⅰ);

尝试这样可以将您的数据用于其他活动

宇宙飞船spaceCraft =(Spacecraft)getIntent()。getSerializableExtra(“image_data”)

© www.soinside.com 2019 - 2024. All rights reserved.