0

我正在尝试使用 Parceler 在两个 Activity 之间发送一个列表。这就是我一直在尝试做的事情:

Intent intent = new Intent(SearchServices.this, MainActivity.class);

intent.putExtra(SearchServices.PARCELER_TAG,Parcels.wrap(
                    new Services(Arrays.asList(sortedArrayr)) ));

startActivity(intent); 

sortedArrayr是一个有效的数组DataSnapshot

Intent intent = this.getIntent();

Log.e("onCreate: ", Parcels.unwrap(intent.getParcelableExtra(SearchServices.PARCELER_TAG)).toString() );

包裹类

@Parcel(Parcel.Serialization.BEAN)
public class Services {

    List<DataSnapshot> ser;

    public Services(List<DataSnapshot> ser) {
        this.ser = ser;
    }

    public Services() {
    }
}

但我不断收到NullPointerException

java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.Object.toString()' on a null object reference
4

0 回答 0