Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/196.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 任务“:app:CompiledBugJavaWithJavaC”的执行失败。“>java.util.NoSuchElementException:列表为空_Android_Android Gradle Plugin_Android Room - Fatal编程技术网

Android 任务“:app:CompiledBugJavaWithJavaC”的执行失败。“>java.util.NoSuchElementException:列表为空

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

我开始在一个新项目中使用Room,并在创建数据库和一些DAO之后开始遇到这个问题。现在gradle甚至不能编译这个项目。见下图:

我很确定这个问题是因为我在房间里犯了一个错误。我在下面附上我的数据模型的代码

基本上,我有一个包含两个实体的数据库:RecipeEntry和IngredEntry。我试着用你在下面看到的方式来模拟这种关系。我还使用名为RecipeWithingElements的POJO来封装在RecipeDao中建模的查询中返回的数据。选择这种方法的原因是Room禁止您以与其他ORM相同的方式对关系进行建模

因为SQLite是一个关系数据库,所以可以指定对象之间的关系。尽管大多数ORM库允许实体对象相互引用,但Room明确禁止这样做

更多信息


有什么线索吗?

在与这个问题争论了几个小时后,我发现问题出在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;
   }
}