J.Doe
J.Doe

Reputation: 45

Adding object of various type to an arraylist

Im having the following objects in my class,

LatestRingtones latestRingtones;
MostDownloadedSongs mostDownloadedSongs;
LatestDialoges latestDialoges;

LatestRingtones, MostDownloadedSongs,LatestDialoges extends sugarrecord.

So, I have created an arraylist to store object of various types as follows,

public List<SugarRecord> streamingTrackList = new ArrayList<>();

I tried to add the latestRingtones as follows

streamingTrackList.add(latestRingtones);

but im getting an error like List can not be applied to jsonarray

How can i be able to convert the jsonarray to list and add it to streaming track or is there any ways through which I can add object of various types to streamingTrack?

Upvotes: 1

Views: 65

Answers (1)

HasS
HasS

Reputation: 201

If latestRingtones is a json array you can not add a JsonArray into ArrayList . So simply convert you jsonarray in Object array using any know library (gson , simple json etc) and than add the objects into your ArrayList

Upvotes: 1

Related Questions