数据绑定错误:找不到符号导入com.example.project_name.package_name

时间:2020-11-05 16:00:37

标签: java android xml

我正在尝试在我的项目中实现dataBinding。添加布局标签并尝试使用变量声明数据后,android studio表示找不到我的类。我正在使用main_activity为imageView存储recyclerView和第二个xml。我想念的是什么?

main_activity.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context=".MainActivity">

    <androidx.recyclerview.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/linear_layout_with_recycleView_ID"/>
</LinearLayout>

single_picture.xml

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
    <data>
        <variable
            name="picture"
            type="com.example.recycleviewpictures.Requests.Responsnes.Pictures" />
    </data>
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <ImageView
        android:layout_width="210dp"
        android:layout_height="200dp"
        android:id="@+id/single_picture_id"/>

</LinearLayout>
</layout>

2 个答案:

答案 0 :(得分:0)

好吧,问题似乎出在软件包的命名上。您不能使用大写字母来命名它们,因为Android Studio将它们视为类。

答案 1 :(得分:0)

执行以下操作:

  • 在Android Studio的“构建”标签中,检查哪个gradle任务失败: enter image description here
  • 选择Android Studio右上方的“成绩”标签: enter image description here
  • 找到失败的gradle任务,然后双击它: enter image description here
  • 让gradle任务完成并查看输出。它应该说“ FAILED”,上面还有几行应该告诉你问题出在哪里: enter image description here