我try 构建应用程序,但一直收到/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.data binding包

this error.

I have tried clean and build also Invalidate and restart

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"
}

activity_detail.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)

    }
}

推荐答案

Do the following.

  1. In Android Studio in your Build tab check which gradle task failed:

enter image description here

  1. Select the "Gradle" tab on the top right of Android Studio:

enter image description here

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

enter image description here

  1. Let the gradle task finish and look at the output. It should say "FAILED" and some lines above that it should tell you what the problem is:

enter image description here

In this example the problem is, that I am using a boolean value for the visibility parameter like so: android:visibility="@{true}" when it should be an Integer, but your data binding error will most likely be something else.

  1. Watch this video and take action.

Kotlin相关问答推荐

只能在元素区域中点击的Jetpack Compose列

Regex(Kotlin)仅匹配句子末尾的句号,而忽略中间的句号,如缩写

Groovy Gradle文件的Kotlin类似功能

Spring Boot 3:为Kotlin中的TestRestTemplate配置读取超时

在 map 中查找键与在 kotlin 中查找 firstOrNull

在kotlin中匹配多个变量

Kotlin 中二叉树的深度

Map.mapTo 到另一个map

Gradle 同步失败:不支持的方法:KotlinPlatformContainer.supports()

Kotlin boxed Int 不一样

在 Scaffold Jetpack Compose 内的特定屏幕上隐藏顶部和底部导航器

验证和 DDD - kotlin 数据类

Jetpack Compose – LazyColumn 不重组

如何使用kotlin中的反射查找包中的所有类

如何暂停kotlin coroutine直到收到通知

Kotlin中具有多个参数的绑定适配器

在 Kotlin 函数上使用 Mokito anyObject() 时,指定为非 null 的参数为 null

Kotlin:测试中的 java.lang.NoSuchMethodError

Java的Kotlin:字段是否可以为空?

Kotlin:在何时使用枚举