I have issue with TypeConverters which I wanted to use to store List of Integers into my room db. But I keep getting issue "Cannot find method 'value'", "Error: element value must be a constant expression", "Error:annotation type not applicable to this kind of declaration" Here is the code.
@Entity
public class Movie {
@PrimaryKey
@SerializedName("id")
private int id;
@ColumnInfo(name = "poster_path")
@SerializedName("poster_path")
private String posterPath;
@ColumnInfo(name = "overview")
@SerializedName("overview")
private String overview;
@ColumnInfo(name = "original_title")
@SerializedName("original_title")
private String title;
@ColumnInfo(name = "release_date")
@SerializedName("release_date")
private String releasedDate;
@ColumnInfo(name = "vote_average")
@SerializedName("vote_average")
private double voteAverage;
@ColumnInfo(name = "genre_ids")
@SerializedName("genre_ids")
private List<Integer> genreIds = null;
public Movie() {
}
public List<Integer> getGenreIds() {
return genreIds;
}
public void setGenreIds(List<Integer> genreIds) {
this.genreIds = genreIds;
}
Converter
public class Converters {
@TypeConverter
public List<Integer> gettingListFromString(String genreIds) {
List<Integer> list = new ArrayList<>();
String[] array = genreIds.split(",");
for(String s: array){
list.add(Integer.parseInt(s));
}
return list;
}
@TypeConverter
public String writingStringFromList(List<Integer> list) {
String genreIds = "";
for(int i : list){
genreIds += ","+i;
}
return genreIds;
}
}
and db
@Database(entities = {Movie.class, Genre.class}, version = 4)
@TypeConverter({Converters.class})
public abstract class AppDatabase extends RoomDatabase {
private static AppDatabase instance;
public static AppDatabase getInstance(Context context){
if(instance == null) instance = Room.databaseBuilder(context, AppDatabase.class, "movies_db")
.build();
return instance;
}
public abstract MovieDao movieDao();
public abstract GenreDao genreDao();
}
Ok finally I have found solution. Instead of
@TypeConverter({Converters.class})
I needed to write
@TypeConverters({Converters.class})
typo.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With