错误:找不到符号导入 com.gorav.news.databinding.ActivityDetailBindingImpl;

2023-11-25

我尝试构建应用程序,但不断收到 /Users/gouravkarwasara/Desktop/News2/app/build/ generated/source/kapt/debug/com/gourav/news/DataBinderMapperImpl.java:9: 错误:找不到符号 导入 com.gourav.news.databinding.ActivityDetailBindingImpl; ^ 符号:类 ActivityDetailBindingImpl 位置:包 com.gourav.news.databinding

这个错误。

我尝试过清理并构建也无效并重新启动

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.gourav.news"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    dataBinding {
        enabled = true
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
   implementation 'androidx.appcompat:appcompat:1.1.0-alpha02'
   implementation 'androidx.core:core-ktx:1.1.0-alpha04'
   implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
   testImplementation 'junit:junit:4.12'
   androidTestImplementation 'androidx.test:runner:1.1.2-alpha01'
   androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.2-alpha01'

   implementation "androidx.lifecycle:lifecycle-extensions:2.0.0"
   kapt "androidx.lifecycle:lifecycle-compiler:2.0.0"
   implementation "androidx.room:room-runtime:2.0.0"
   kapt "androidx.room:room-compiler:2.0.0"
   implementation 'com.google.android.material:material:1.1.0-alpha03'

   implementation "com.squareup.retrofit2:retrofit:2.4.0"
   implementation "com.squareup.retrofit2:converter-gson:2.4.0"
   implementation "com.squareup.okhttp3:logging-interceptor:3.11.0"

   // Retrofit for networking
   implementation "com.squareup.retrofit2:retrofit:2.4.0"
   implementation "com.squareup.retrofit2:converter-gson:2.4.0"
   implementation "com.squareup.okhttp3:logging-interceptor:3.11.0"

   //Timber for logging
   implementation "com.jakewharton.timber:timber:4.7.1"

   // Image Loading and Caching
   implementation "com.github.bumptech.glide:glide:4.8.0"
   annotationProcessor "com.github.bumptech.glide:compiler:4.8.0"
   implementation "com.google.firebase:firebase-core:16.0.7"
}

活动详细信息.xml

<?xml version="1.0" encoding="utf-8"?>
<layout>

<data>

    <import type="com.gourav.news.utils.BindingUtils" />

    <variable
            name="article"
            type="com.gourav.news.model.Article" />
</data>

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            xmlns:tools="http://schemas.android.com/tools"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            xmlns:bind="http://schemas.android.com/apk/res-auto">

    <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingBottom="16dp"
            tools:context=".DetailActivity">

        <View
                android:layout_width="0dp"
                android:layout_height="0dp"
                app:layout_constraintBottom_toBottomOf="@id/tv_news_source"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@id/iv_news_image" />

        <ImageView
                android:id="@+id/iv_news_image"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:contentDescription="@string/image_desc"
                android:foreground="@drawable/news_image_gradient"
                app:layout_constraintDimensionRatio="h,16:9"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                bind:articleUrl="@{article.url}"
                bind:urlToImage="@{article.urlToImage}" />

        <ImageButton
                android:id="@+id/iv_save"
                android:layout_width="48dp"
                android:layout_height="48dp"
                android:layout_marginEnd="4dp"
                android:background="?selectableItemBackgroundBorderless"
                android:contentDescription="@string/image_desc_save_button"
                app:layout_constraintEnd_toStartOf="@id/iv_share"
                app:layout_constraintTop_toTopOf="@id/tv_time"
                app:srcCompat="@drawable/ic_save" />

        <ImageButton
                android:id="@+id/iv_share"
                android:layout_width="48dp"
                android:layout_height="48dp"
                android:background="?selectableItemBackgroundBorderless"
                android:contentDescription="@string/image_desc_share_button"
                app:layout_constraintEnd_toStartOf="@id/guideline_right"
                app:layout_constraintTop_toTopOf="@id/tv_time"
                app:srcCompat="@drawable/ic_share" />

        <TextView
                android:id="@+id/tv_time"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="16dp"
                android:text="@{BindingUtils.formatDateForDetails(article.publishedAt)}"
                android:textSize="16sp"
                android:textStyle="bold"
                app:layout_constraintStart_toStartOf="@id/guideline_left"
                app:layout_constraintTop_toBottomOf="@+id/tv_news_title"
                tools:text="@tools:sample/date/ddmmyy" />

        <TextView
                android:id="@+id/tv_news_source"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="4dp"
                android:paddingBottom="18dp"
                android:text="@{article.source.name}"
                android:textSize="16sp"
                android:textStyle="bold"
                app:layout_constraintStart_toStartOf="@id/guideline_left"
                app:layout_constraintTop_toBottomOf="@id/tv_time"
                tools:text="The Washington Post" />

        <TextView
                android:id="@+id/tv_news_title"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="16dp"
                android:lineSpacingMultiplier="1.1"
                android:text="@{article.title}"
                android:textColor="@color/colorAccent"
                android:textSize="24sp"
                android:textStyle="bold"
                app:layout_constraintEnd_toEndOf="@id/guideline_right"
                app:layout_constraintStart_toStartOf="@id/guideline_left"
                app:layout_constraintTop_toBottomOf="@id/iv_news_image"/>

        <TextView
                android:id="@+id/tv_news_desc"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="32dp"
                android:alpha="0.6"
                android:lineSpacingMultiplier="1.3"
                android:text="@{article.description}"
                android:textColor="@color/colorAccent"
                android:textSize="18sp"
                app:layout_constraintEnd_toEndOf="@id/guideline_right"
                app:layout_constraintStart_toStartOf="@id/guideline_left"
                app:layout_constraintTop_toBottomOf="@id/tv_news_source"
                tools:layout_editor_absoluteY="365dp"/>

        <TextView
                android:id="@+id/tv_news_content"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="32dp"
                android:alpha="0.6"
                android:lineSpacingMultiplier="1.3"
                android:text="@{BindingUtils.truncateExtra(article.content)}"
                android:textColor="@color/colorAccent"
                android:textSize="18sp"
                app:layout_constraintEnd_toEndOf="@id/guideline_right"
                app:layout_constraintStart_toStartOf="@id/guideline_left"
                app:layout_constraintTop_toBottomOf="@id/tv_news_desc"/>

        <Button
                android:id="@+id/btn_read_full"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="32dp"
                android:background="@drawable/button_selector"
                android:paddingStart="16dp"
                android:paddingEnd="16dp"
                android:text="@string/button_read_full_story"
                android:textSize="16sp"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@id/tv_news_content" />

        <androidx.appcompat.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:background="?actionBarItemBackground"
                android:fitsSystemWindows="true"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:navigationIcon="@drawable/ic_close" />

        <androidx.constraintlayout.widget.Guideline
                android:id="@+id/guideline_left"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                app:layout_constraintGuide_begin="12dp" />

        <androidx.constraintlayout.widget.Guideline
                android:id="@+id/guideline_right"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                app:layout_constraintGuide_end="12dp" />

        <androidx.constraintlayout.widget.Barrier
                android:id="@+id/bottom_barrier"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:barrierDirection="bottom"
                app:constraint_referenced_ids="tv_news_desc,tv_news_content,tv_news_title" />

    </androidx.constraintlayout.widget.ConstraintLayout>

</ScrollView>
</layout>

详细活动.kt

class DetailActivity : AppCompatActivity() {
    private lateinit var binding: ActivityDetailBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = DataBindingUtil.setContentView(this, R.layout.activity_detail)

    }
}

请执行下列操作。

  1. 在 Android Studio 的“构建”选项卡中检查哪个 gradle 任务失败:

enter image description here

  1. 选择Android Studio右上角的“Gradle”选项卡:

enter image description here

  1. 找到失败的gradle任务并双击它:

enter image description here

  1. 让 gradle 任务完成并查看输出。它应该显示“FAILED”以及上面的一些行,它应该告诉您问题是什么:

enter image description here

在此示例中,问题是,我对可见性参数使用布尔值,如下所示:android:visibility="@{true}"当它应该是一个整数时,但您的数据绑定错误很可能是其他东西。

  1. 看这个视频 and take action.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

错误:找不到符号导入 com.gorav.news.databinding.ActivityDetailBindingImpl; 的相关文章

  • 如何在 Kotlin Android 中正确使用 URL

    我想用 override fun onCreate savedInstanceState Bundle super onCreate savedInstanceState setContentView R layout activity m
  • Kotlin 中的数据绑定无法与视图绑定一起使用

    安卓工作室3 6 构建 gradle buildscript ext kotlin version 1 3 50 repositories google jcenter dependencies classpath com android
  • 如何避免数据绑定的“警告:[cast]冗余转换为字符串”

    Android Studio 会生成大量警告 如下所示 fooBindingImpl java 106 警告 cast 冗余强制转换为 String fooActivityOfUserName set java lang String ca
  • LiveData无法观察到变化

    我正在更新一个ViewModel 中 DialogFragment 的 LiveData 值 但无法获取Fragment中的值 视图模型 class OtpViewModel private val otpUseCase OtpUseCas
  • 使用 Jetpack Compose 中的导航抽屉在可组合项之间导航

    我正在尝试在 jetpack compose 中为抽屉图标 文本字段设置导航 但不确定如何正确执行 如何设置导航 以便每当我单击其中一个图标时 我都会导航到该可组合屏幕 这是目前我的主抽屉布局 Composable fun MainDraw
  • @Service 中带有 Kotlin 的 Spring Boot @Autowired 始终为 null

    目前 我尝试使用 Kotlin 重写我的 Java Spring Boot 应用程序 我遇到了一个问题 在我所有的类中都用 Service依赖注入无法正常工作 所有实例都null 这是一个例子 Service Transactional o
  • kotlin中的三元运算符[重复]

    这个问题在这里已经有答案了 我可以用java写 int i 10 String s i 10 Ten Empty 即使我可以将它传递到方法参数中 callSomeMethod i 10 Ten Empty 如何将其转换为 kotlin 在
  • 如何在Dialog中使用数据绑定?

    我在对话框中实现数据绑定时遇到问题 是否可以 下面是我的 xml
  • Kotlin 1.6.0 的 proguard / R8 删除了数据类元数据

    我有一个包含一些数据类的包 我尝试使用 Kotlin 反射在运行时访问构造函数clazz primaryConstructor 一切都按预期工作 但是当我启用 R8 时 数据类元数据被删除 例如当我检查是否KClass isData它返回
  • Ktor 如何处理空响应

    我使用 Ktor 和这样的线路myentity client get url 从 API 响应获取并反序列化我的实体 当 API 返回某些内容时它工作正常 但是一旦 API 没有任何可返回的内容并发送 HTTP 204 响应 它就会失败并显
  • Android:如何根据视图模型实时数据属性为片段编写单元测试?

    我的片段 UI 中有一个列表视图 其元素集取决于来自视图模型 LiveData 属性的值的状态 我想为片段创建工具测试 该片段包含与该属性的值集相关的 3 个场景测试用例 但我不知道从哪里开始 我的代码应该如下所示 class MyView
  • Kotlin 协程阻塞 Android 中的主线程

    我是 Kotlin 和协程的新手 我有一个fun在我的活动及其内部 检查User用户名和密码 如果为真 则返回Users object 一切都好 但是当我按下按钮时 我的活动被阻止并等待响应Users login 我用这个有趣的 priva
  • 如何使用 jackson 反序列化为 Kotlin 集合

    我想要的示例代码 data class D val a String val b Int val jsonStr a value1 b 1 a value2 b 2 what I need val listOfD List
  • Moshi 无法解析 nullable

    你好 希望你能帮助我 使用 kotlin Retrofit2 moshi 我从 https api spacexdata com v3 launches 获取数据并解析它 一切都很顺利 我得到的属性如下 flight number miss
  • 在viewpager2中禁用动画

    我有 viewpager2 和扩展 FragmentStateAdapter 的适配器 我希望用户仅通过单击选项卡布局即可转到另一个页面 我已禁用此 viewpager2 的用户输入 但是当我单击选项卡时 有页面之间快速滑动的动画 但我只想
  • Jetpack Compose:制作全屏(绝对定位)组件

    我怎样才能在全屏渲染树的深处制作一个可组合的 类似于Dialog可组合作品 例如 当用户单击图像时 它会显示该图像的全屏预览 而无需更改当前路线 我可以用 CSS 来做到这一点position absolute or position fi
  • 调试android数据绑定?

    谁能告诉我如何调试或找到数据绑定生成的代码 从this https www youtube com watch v NBbeQMOcnZ0链接我发现它生成了所需的代码 我猜您正在寻找自动生成的绑定 java 文件 我也在寻找他们 最后我在这
  • Kotlin 未解决的参考:CLI 上 gradle 的 println

    放一个printlnkotlin 函数返回之前的语句会崩溃 堆栈跟踪 thufir dur NetBeansProjects kotlin thufir dur NetBeansProjects kotlin gradle clean bu
  • 让协程等待之前的调用

    我还没有完全掌握 Kotlin 协程 基本上我希望协程在执行之前等待任何先前的调用完成 下面的代码似乎可以工作 但它正在做我认为它正在做的事情吗 private var saveJob Job null fun save saveJob s
  • 在 Jetpack Compose 中启动动画矢量 Drawable

    我有一个动画矢量可绘制R drawable my anim 我想在 Jetpack Compose 中展示并开始 可绘制对象显示 渲染正确 但动画未启动 这是撰写视图 Composable fun SplashView Surface mo

随机推荐