我想从 Sharedpreference 中存储和检索我的自定义对象 Arralist,我已经尝试过但收到编译时错误
有人可以帮忙吗?
代码:
@Override protected void onPause() {
List<Movie> movieList;
super.onPause();
//save the movie list to preference
SharedPreferences preferences = getPreferences(MODE_PRIVATE);
Editor editor = preferences.edit();
try {
editor.putString("movies", org.apache.pig.impl.util.ObjectSerializer.serialize(movieList));
} catch (IOException e) {
e.printStackTrace();
}
editor.commit();
}
}
这是要成为的模型类:
public class Movie implements Serializable {
private static final long serialVersionUID = 1L;
private String MovieName;
private String MovieActor;
private String MovieActress;
private String MovieDirector;
private String MovieImage;
private String MovieDescription;
private String MovieWatchLink;
public String getMovieName() {
return MovieName;
}
public void setMovieName(String movieName) {
MovieName = movieName;
}
public String getMovieActor() {
return MovieActor;
}
public void setMovieActor(String movieActor) {
MovieActor = movieActor;
}
public String getMovieActress() {
return MovieActress;
}
public void setMovieActress(String movieActress) {
MovieActress = movieActress;
}
public String getMovieDirector() {
return MovieDirector;
}
public void setMovieDirector(String movieDirector) {
MovieDirector = movieDirector;
}
public String getMovieImage() {
return MovieImage;
}
public void setMovieImage(String movieImage) {
MovieImage = movieImage;
}
public String getMovieDescription() {
return MovieDescription;
}
public void setMovieDescription(String movieDescription) {
MovieDescription = movieDescription;
}
public String getMovieWatchLink() {
return MovieWatchLink;
}
public void setMovieWatchLink(String movieWatchLink) {
MovieWatchLink = movieWatchLink;
}
编译时错误:
The method serialize(Serializable) in the type ObjectSerializer is not applicable for the
arguments (List<Movie>)