작성
·
955
0
안녕하세요 아래와 같이 작성하였는데
바인딩 에러가 나는 이유를 모르겠어서 질문 올립니다!
Caused by: android.view.InflateException: Binary XML file line #18 in com.example.coco:layout/activity_intro: Binary XML file line #18 in com.example.coco:layout/activity_intro: Error inflating class androidx.fragment.app.FragmentContainerView
Caused by: android.view.InflateException: Binary XML file line #18 in com.example.coco:layout/activity_intro: Error inflating class androidx.fragment.app.FragmentContainerView
package com.example.coco.view.intro
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import androidx.activity.viewModels
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.lifecycle.Observer
import com.example.coco.MainActivity
import com.example.coco.databinding.ActivityIntroBinding
// Splash 화면 만들기
class IntroActivity : AppCompatActivity() {
private lateinit var binding : ActivityIntroBinding
private val viewModel: IntroViewModel by viewModels()
override fun onCreate(savedInstanceState: Bundle?) {
installSplashScreen()
binding = ActivityIntroBinding.inflate(layoutInflater)
super.onCreate(savedInstanceState)
setContentView(binding.root)
viewModel.checkFirstFlag()
viewModel.first.observe(this, Observer {
if (it){
// 처음 접속하는 유저가 아님
val intent = Intent(this, MainActivity::class.java)
startActivity(intent)
}else{
// 처음 접속하는 유저
binding.fragmentContainerView.visibility = View.VISIBLE
}
})
}
}
답변 2
0
<?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=".view.intro.IntroActivity">
<androidx.fragment.app.FragmentContainerView
android:id="@+id/fragmentContainerView"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:navGraph="@navigation/main_nav"
tools:layout_editor_absoluteX="1dp"
android:visibility="invisible"
tools:layout_editor_absoluteY="1dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
IntroActivity에서
binding과 super.onCreate / installsplashscreen()등의 순서가 잘못되었네요.
아래와 같이 변경해보시겠어요?
class IntroActivity : AppCompatActivity() {
lateinit var binding: ActivityIntroBinding
private val viewModel: IntroViewModel by viewModels()
override fun onCreate(savedInstanceState: Bundle?) {
installSplashScreen()
super.onCreate(savedInstanceState)
binding = ActivityIntroBinding.inflate(layoutInflater)
setContentView(binding.root)
viewModel.checkFirstFlag()
viewModel.first.observe(this, Observer {
if (it){
// 처음 접속하는 유저가 아님
val intent = Intent(this, MainActivity::class.java)
startActivity(intent)
}else{
// 처음 접속하는 유저
binding.animationView.visibility = View.INVISIBLE
binding.fragmentContainer.visibility = View.VISIBLE
}
})
}
}
0
여기까지 문제가 없어보이는데
코드를 깃허브에 올리시고 링크를 공유해주시겠어요?
제가 확인해보겠습니다.