gpt4 book ai didi

Java, 安卓 : ClassCastException after Intent

转载 作者:行者123 更新时间:2023-11-30 10:52:07 25 4
gpt4 key购买 nike

<分区>

我有类(class)播放列表

public class Playlist extends ArrayList<Track> implements Serializable {

String module;
String name, playlistId;

public Playlist(String name) {
super();
this.name = name;
}
...
}

我尝试将其赋予 Intent:

...
Intent intent = new Intent(this, PlaylistActivity.class);
intent.putExtra("playlist", Modul.loaded[id].getPlaylist(pId)); //Return Playlist
startActivity(intent);

当我尝试获取播放列表时:

Intent intent = getIntent();
playlist = (Playlist) intent.getSerializableExtra("playlist");

这里我得到了这个错误:

Caused by: java.lang.ClassCastException: java.util.ArrayList cannot be cast to com.timia2109.nukla.Playlist

但它必须是一个播放列表,因为我将它创建为一个播放列表,并且我不会将它转换为带有 Intent 的可序列化对象。我在互联网上没有找到解决方案,但我什么也没找到。

或者有没有办法做到这一点:

PlaylistActivity pa = new PlaylistActivity();
pa.setPlaylist( playlist );
//And now start this Activity

谢谢!

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com