Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find method 'value' on Converters.class in room

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();

}
like image 797
Vladan Jovanovic Avatar asked Nov 01 '17 15:11

Vladan Jovanovic


1 Answers

Ok finally I have found solution. Instead of

@TypeConverter({Converters.class})

I needed to write

@TypeConverters({Converters.class})

typo.

like image 116
Vladan Jovanovic Avatar answered Nov 04 '22 01:11

Vladan Jovanovic