-
Notifications
You must be signed in to change notification settings - Fork 261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
inflating error #18
Comments
Caused by: android.view.InflateException: Binary XML file line #24: Binary XML file line #24: Error inflating class fragment |
For me Also Same Error I am getting Sir What is the solution for that |
Caused by: android.view.InflateException: Binary XML file line #25 in com.talla.binchecker:layout/activity_main: Binary XML file line #25 in com.talla.binchecker:layout/activity_main: Error inflating class fragment |
I replaced this line "val newsRepository = NewsRepository(ArticleDatabase(requireContext())) |
Same thing worked to me bro
…On Thu, 23 Sep, 2021, 11:13 am Tarun Kumar, ***@***.***> wrote:
I replaced this line
"viewModel = (activity as NewsActivity).viewModel"
from every fragment with this
"val newsRepository = NewsRepository(ArticleDatabase(requireContext()))
val vmProviderFactory = NewsVMProviderFactory(newsRepository)
viewModel = ViewModelProvider(this,
vmProviderFactory).get(NewsViewModel::class.java)
"
and it worked.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#18 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AML7WRDHNOYNF6EL4Z2KPALUDK5ARANCNFSM5BICFNFQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
But I have doubt why this line not working
viewModel = (activity as NewsActivity).viewModel"
|
`Hi guys, the solution is quite simple...
` The view must be created after the ViewModel setup, since every fragment will be refering the NewsActivity. That will do the trick for sure. |
Don't use FrameLayout So change it like this activity_news.xml
NewsActivity class NewsActivity : AppCompatActivity() {
} androidx.fragment.app.FragmentContainerView is a part of the AndroidX library that improved the shortcomings of FrameLayout. |
im getting
Caused by: android.view.InflateException: Binary XML file line #25 in com.androiddevs.mvvmnewsapp:layout/activity_news: Binary XML file line #25 in com.androiddevs.mvvmnewsapp:layout/activity_news: Error inflating class fragment
Caused by: android.view.InflateException: Binary XML file line #25 in com.androiddevs.mvvmnewsapp:layout/activity_news: Error inflating class fragment
Caused by: kotlin.UninitializedPropertyAccessException: lateinit property viewModel has not been initialized
at com.androiddevs.mvvmnewsapp.ui.NewsActivity.getViewModel(NewsActivity.kt:15)
at com.androiddevs.mvvmnewsapp.ui.fragments.BreakingNewsFragment.onViewCreated(BreakingNewsFragment.kt:25)
and app crashes
The text was updated successfully, but these errors were encountered: