강의

멘토링

커뮤니티

인프런 커뮤니티 질문&답변

동해물과백두산이마르고닳도록님의 프로필 이미지
동해물과백두산이마르고닳도록

작성한 질문수

[왕초보편] 앱 8개를 만들면서 배우는 안드로이드 코틀린(Android Kotlin)

데이터바인딩(Databinding) 설명

layout 태그로 감쌀 때 앱 실행 중단 됨 오류

해결된 질문

작성

·

299

0

강의 위치 : 주사위 만들기 첫 번째 강의 <layout> 태그로 

감싸는 부분

 

에러 내용 : activity_main.xml 에서,  layout태그로 감싸지 않았을 때는 정상적으로 

앱 실행이 되는데, 감싸기만 하면 앱이 계속 중단되는 문제 발생합니다. 왜 그런지 알려주시면 정말 감사하겠습니다.

// 문제의 코드 : 앱이 제대로 실행되지 않고 바로 종료되어버림

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

<layout>

    <androidx.constraintlayout.widget.ConstraintLayout 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"
        tools:context=".MainActivity">

        <Button
            android:id="@+id/testBtnId"
            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" />

    </androidx.constraintlayout.widget.ConstraintLayout>

</layout>

// 정상적으로 실행되는 코드
<?xml version="1.0" encoding="utf-8"?>

<androidx.constraintlayout.widget.ConstraintLayout 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"
    tools:context=".MainActivity">

    <Button
        android:id="@+id/testBtnId"
        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" />

</androidx.constraintlayout.widget.ConstraintLayout>

답변 2

0

개복치개발자님의 프로필 이미지
개복치개발자
지식공유자

또한 에러 내용도 공유해주시면 살펴보겠습니다

감사합니다. 같은 내용의 새로운 질문으로 다시 올렸습니다!

0

개복치개발자님의 프로필 이미지
개복치개발자
지식공유자

혹시 build.gradle에 아래의 부분 추가하셨나요?

 

buildFeatures {
dataBinding true
}

 

만약 그렇다면 아래의 코드 3개를 모두 복사해서 공유해주세요.

 

MainActivity.kt

activity_main.xml

build.gradle

동해물과백두산이마르고닳도록님의 프로필 이미지
동해물과백두산이마르고닳도록

작성한 질문수

질문하기