Android 任务“:app:CompiledBugJavaWithJavaC”的执行失败。“>java.util.NoSuchElementException:列表为空
我开始在一个新项目中使用Room,并在创建数据库和一些DAO之后开始遇到这个问题。现在gradle甚至不能编译这个项目。见下图: 我很确定这个问题是因为我在房间里犯了一个错误。我在下面附上我的数据模型的代码 基本上,我有一个包含两个实体的数据库:RecipeEntry和IngredEntry。我试着用你在下面看到的方式来模拟这种关系。我还使用名为RecipeWithingElements的POJO来封装在RecipeDao中建模的查询中返回的数据。选择这种方法的原因是Room禁止您以与其他ORM相同的方式对关系进行建模 因为SQLite是一个关系数据库,所以可以指定对象之间的关系。尽管大多数ORM库允许实体对象相互引用,但Room明确禁止这样做 更多信息Android 任务“:app:CompiledBugJavaWithJavaC”的执行失败。“>java.util.NoSuchElementException:列表为空,android,android-gradle-plugin,android-room,Android,Android Gradle Plugin,Android Room,我开始在一个新项目中使用Room,并在创建数据库和一些DAO之后开始遇到这个问题。现在gradle甚至不能编译这个项目。见下图: 我很确定这个问题是因为我在房间里犯了一个错误。我在下面附上我的数据模型的代码 基本上,我有一个包含两个实体的数据库:RecipeEntry和IngredEntry。我试着用你在下面看到的方式来模拟这种关系。我还使用名为RecipeWithingElements的POJO来封装在RecipeDao中建模的查询中返回的数据。选择这种方法的原因是Room禁止您以与其他ORM
有什么线索吗?在与这个问题争论了几个小时后,我发现问题出在RecipeWithingElements POJO中。您需要在列表中指定要返回的对象的类型,否则文件室将出现问题。如果房间开发者能够打印出这方面的任何信息,那就太酷了。当前的错误描述没有太大帮助。 修改后的代码如下:
public class RecipeWithIngredients {
@Embedded
private RecipeEntry recipe;
@Relation(parentColumn = "id", entityColumn = "recipe_id", entity = IngredientEntry.class)
private List<IngredientEntry> ingredients;
public RecipeEntry getRecipe() {
return recipe;
}
public void setRecipe(RecipeEntry recipe) {
this.recipe = recipe;
}
public List<IngredientEntry> getIngredients() {
return ingredients;
}
public void setIngredients(List<IngredientEntry> ingredients) {
this.ingredients = ingredients;
}
}
public class RecipeWithIngredients {
@Embedded
private RecipeEntry recipe;
@Relation(parentColumn = "id", entityColumn = "recipe_id", entity = IngredientEntry.class)
private List<IngredientEntry> ingredients;
public RecipeEntry getRecipe() {
return recipe;
}
public void setRecipe(RecipeEntry recipe) {
this.recipe = recipe;
}
public List<IngredientEntry> getIngredients() {
return ingredients;
}
public void setIngredients(List<IngredientEntry> ingredients) {
this.ingredients = ingredients;
}
}