Невозможно импортировать класс привязки данных в Android Studio - PullRequest
0 голосов
/ 29 мая 2019

Я не могу импортировать класс данных .

Вот мой build.gradle

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.test1"
        minSdkVersion 23
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

        dataBinding {
            enabled = true
        }

    }

      .......

А вот мой MainActivity.kt

package com.example.test1

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import com.example.test1.databinding // <-- Shows ERROR in this line

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
    }
}

вот мой Activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools">
<android.support.constraint.ConstraintLayout

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

    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Hello World!"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent"/>

</android.support.constraint.ConstraintLayout>
</layout>

Я синхронизировал Gradle, я также попытался перезапустить Android Studio, но он просто не будет работать.

Что мне делать?

1 Ответ

0 голосов
/ 29 мая 2019

Изменить положение переплета:

android {
    compileSdkVersion 28
    dataBinding {
        enabled = true
    }

    defaultConfig {
        applicationId "com.example.test1"
        minSdkVersion 23
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner"android.support.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}
...